嗨 我在我的窗口应用程序窗体中使用datagridview。我希望当我点击datagridview的特定列时,它会弹出一个包含该字段的信息的窗口。就像我有关于datagridveiw中stds的所有数据,但不是显示所有我只想显示他/她的名字的信息,其他信息应该通过点击该特定名称来显示。如何使用c#在窗口应用程序中单击datagridview列来显示弹出窗口?
问候 Touseef
嗨 我在我的窗口应用程序窗体中使用datagridview。我希望当我点击datagridview的特定列时,它会弹出一个包含该字段的信息的窗口。就像我有关于datagridveiw中stds的所有数据,但不是显示所有我只想显示他/她的名字的信息,其他信息应该通过点击该特定名称来显示。如何使用c#在窗口应用程序中单击datagridview列来显示弹出窗口?
问候 Touseef
试试这个
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
Form1 frm = new Form1(DataGridView1.CurrentRow.Cells["ID"].Value.ToString()));
frm .ShowDialog();
}
catch (Exception ex)
{
}
}
在此代码ü要显示为弹出另一种形式的创建对象。 // Form1 frm = new Form1.
而且考取ID值作为构造函数的形式Form1
并显示为对话// DataGridView1.CurrentRow.Cells["ID"].Value
也将Form 1 ShowInTaskBar属性来False
注:
您可以访问该构造函数值(ID)从Form1并获取所有详细信息ID并显示为你的愿望
你可以尝试这样的:
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);
}
}
见MSDN
私人无效DataGridView_CellClick(对象发件人,DataGridViewCellEventArgs E) { 尝试 { Viewaddeduser FRM =新Viewaddeduser(DataGridView.CurrentRow .Cells [ “FileNo在”] Value.ToString());。 frm .ShowDialog(); } catch(Exception ex) { MessageBox.Show(“Ok”+ ex); } } – 2011-05-21 11:38:33
它给出异常 – 2011-05-21 11:38:45
和viewadded用户表单private String FileNo; public Viewaddeduser(String FileNo) { InitializeComponent(); } 它是正确的方式? – 2011-05-21 11:39:39