[英]How to get Selected Row Contents from DataGridView in C#?
如何從C#中的DataGridView獲取選定的行內容
我有一個9列的DataGridView。 我從具有20列的Stdn_Registration_tbl(表)中填充這些列(我的意思是我只為GridView選擇了特定的列)。 現在我想當有人在“選定行”上單擊鼠標右鍵時,它會彈出一個ContextMenuStrip。
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
contextMenuStrip1.Show(searchStdn_dtGv, e.Location);
}
然后,單擊“ 查看” (上下文菜單項)后,它將以另一種形式(form2)顯示來自Stdn_Registration_tbl的所有數據。
將DataGridViewRow從Form1傳遞到Form2:
//In Form1
DataGridViewRow r = dataGridView1.SelectedRows[0];
Form2 f = new Form2();
f.row = r;
f.ShowDialog();
//In Form2
public DataGridViewRow row;
private void Form2_Load(object sender, EventArgs e)
{
label1.text = row.cell[0].ToString();
.
.
.
label9.text = row.cell[8].ToString();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.