I have only datagridView in Form1 . What I want is when I select DataGridView Row it will show me Form2 and Displayed their values in TextBoxs of it.
Please, Can somebody have any idea?
Thanks in Advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vinay SinghRank #604 · 4K reputationPosted Jun 23, 2016, 1:47 AM EDT
private void dataGridView_SelectionChanged(object sender, EventArgs e)
{
DataGridViewCell cell = null;
foreach (DataGridViewCell selectedCell in dataGridView.SelectedCells)
{
cell = selectedCell;
break;
}
if (cell != null)
{
DataGridViewRow row = cell.OwningRow;
string form1_Id= row.Cells["ID"].Value.ToString();
string form1_Name = row.Cells["Name"].Value.ToString();
Form2 objform2 = new Form2();
objform2.Form2Id= form1_Id;
objform2.Form2Id= form1_Name;
objform2.Show();
}
}
Now on Form2 Page load
public string Form2Id= "";
public string Form2Name= "";
private void Form2_Load(object sender, EventArgs e)
{
txtId.Text = Form2Id;
txtName.Text = Form2Id;
}
Nirav DaraniyaRank #593 · 4.1K reputationPosted Jun 23, 2016, 1:44 AM EDT
Rose Rouge27 reputationPosted Jun 23, 2016, 2:19 AM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 23, 2016, 2:24 AM EDT
Rose Rouge27 reputationPosted Jun 23, 2016, 3:09 AM EDT
When I click to open Form 1 , it's open Form1 and form2 at the same time and when I select a row, it show me Form2 but with Textboxes empties.
Vinay SinghRank #604 · 4K reputationPosted Jun 23, 2016, 3:36 AM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 23, 2016, 4:02 AM EDT
Rose Rouge27 reputationPosted Jun 23, 2016, 4:04 AM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 23, 2016, 8:58 AM EDT