开发者

How could i load a form corresponding to the cell clicked in datagrid

开发者 https://www.devze.com 2023-01-12 16:32 出处:网络
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 t

Hi all i will have some data in my datagrid as follows

How could i load a form corresponding to the cell clicked in datagrid

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消