How could i load a form corresponding to the cell clicked in datagrid
Hi all i will have some data in my datagrid as follows
Now if i click on first column on any开发者_如何学C cell i would like to show a from, and if i click on 2nd row on any cell value i would like to show another form. How can i do this...
I got the answer
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string s = dataGridView1.CurrentCell.RowIndex.ToString();
if (Convert.ToInt32(s) == 0)
{
Form f = new Form();
ActivateMdiChild(f);
f.Show();
}
if (Convert.ToInt32(s) == 1)
{
MessageBox.Show("Hi");
}
}
You need to keep some value identifying form to launch in the data table (or in hidden column). Now, in click event, you can look up for that value within current row and launch the needed form.
精彩评论