嗨 我在我的窗口應用程序窗體中使用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