开发者

how to show popup by clicking on datagridview column in window application using c#?

hi I am using datagridview in my window application form. I want that when I click on a particular column of datagridview it popup a window having info containing thatfield. Like I have all data about stds in datagridveiw, but instead of displaying all I want to display only his/her name, rest of information should be appear by clicking on that particular name.

Regards Tousee开发者_如何学Cf


you can try something like:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        String info;

        if (e.ColumnIndex == 0) // Here specify the column index on click of which you want to display popup
        {
            //your logic here
            info= dataGridView1.Rows[e.RowIndex].Cells["U_ID"].Value).toString();  // Cells["<specify your cell name for this index>"]
            MessageBox.Show(info);
        }

        else if (e.ColumnIndex == 1) // Here specify the column index on click of which you want to display popup
        {
            //your logic here
            info= dataGridView1.Rows[e.RowIndex].Cells["Name"].Value).toString();  // Cells["<specify your cell name for this index>"]
            MessageBox.Show(info);
        }
    }

See MSDN


Try this

private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                Form1 frm = new Form1(DataGridView1.CurrentRow.Cells["ID"].Value.ToString())); 
                frm .ShowDialog();

            }
            catch (Exception ex)
            {
            }

        }

In this code your creating object of another form which u want to show as popup. //Form1 frm = new Form1.

And pasing ID value as constructor to those form Form1 and show as dialogue //DataGridView1.CurrentRow.Cells["ID"].Value

Also set Form1 ShowInTaskbar property to False

NOTE:

You can access that constructor value(ID) from Form1 and fetch all details by ID and display as your wish

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜