중복 질문 일 수 있지만 이전 질문으로 문제가 해결되지 않았습니다.
나는 Form1
및 Form2
. 에서 Form1
이있다 dataGridView
라는 필드 category
.
에서 form2
나는를 설정 combobox
. 나는 필드에서 데이터를 전송 category
의 dataGridView
에서 form1
이것 combobox
에서 Form2
.
나는 identifier
이것을 combobox
공개했다. 가 update button
에가 Form1
.
내가 행을 선택하고 클릭 할 때 내가 원하는 update button
, Form2
열리고 combobox
있다 그 필드의 값을 보여줍니다 category
의 dataGridView
의를Form1.
다음은 코드입니다.
Form2 fr2 = new Form2();
fr2.cmbCategory.Text = dgvProduct.SelectedRows[0].Cells[1].Value.ToString();
fr2.Show();
그런 다음에 Form2
내가 설정 한 DataSource
의 cmbCategory
에를 tblCategory
, 그리고 그것의 설정 Display member
필드 code
.
내가 원하는 cmbCategory
모든 항목을 표시하도록 field code
에서를 tblCategory
동시에, 그 항목 중 하나가 선택 될 수있다. 따라서 선택한 항목은 내가 전달한 항목이어야합니다 Form1
.
어떻게 할 수 있을까? 저는 코딩에 익숙하지 않으며 간단한 방법으로 답변 해주시면 정말 감사합니다. 이 모든 작업을 수행하기 위해 Visual C #을 사용했습니다.
이렇게 할 수 있습니다
업데이트 됨 : SelectedItem 대신 텍스트 사용
당신의에서 Form1에 연사 파일 :
private void UpdateButton_Click_1(object sender, EventArgs e)
{
int category = 0;
Int32.TryParse(dgvProduct.SelectedRows[0].Cells[1].Value.ToString(), out category);
Form2 fr2 = new Form2(category); // You are calling parameterized constructor for Form2
fr2.Show();
}
이제 Form2 cs 파일에서 :
public partial class Form2 : Form
{
public int Category { get; set; } // Property for selected category (You need this only if you need the category outside Form2 constructor)
public Form2() // Default constructor
{
InitializeComponent();
}
public Form2(int category) // Contructor with string parameter
{
Category = category;
InitializeComponent();
cmbCategory.Text = Category.ToString(); **// Use Text property instead of SelectedItem.**
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다