[英]How to get all the values of the selected row of a Grid in Windows form?
I have created a windows form in which I have a grid "gridVerificationQ". 我创建了一个Windows窗体,其中有一个网格“ gridVerificationQ”。 This grid contains different columns whose values gets all the bank account information a person have.
该网格包含不同的列,这些列的值获取一个人拥有的所有银行帐户信息。 I want to get all the values of a grid row that is selected, but I am finding a hard time in getting it.
我想获取选中的网格行的所有值,但是我很难找到它。 I know its a very small thing but still i would appreciate the help provided.
我知道这是一件很小的事情,但我仍然感谢提供的帮助。
dataGridView1.SelectedRows[0].Cell["CellName"].Value
Set DataGridView.MultiSelect =false and DataGridView.SelectionMode = FullRowSelect. 设置DataGridView.MultiSelect = false和DataGridView.SelectionMode = FullRowSelect。 This will make it so the user can only select a single row at a time.
这样可以使用户一次只能选择一行。
Or use for loop 或用于循环
foreach(DataGridViewCell cell in dataGridView1.SelectedRows[0].Cells)
{
if(cell.Value != null)
{
//your code
}
}
Use the SelectedIndexChanged
event as: 将
SelectedIndexChanged
事件用作:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e){
Message.Text = GridView1.SelectedRow.Cells[0].Text;
// you can use loop to iterate through all the cells of the row.
}
您可以获取所选行的列的值,例如:
int AccountId= (int)dataGridView1.SelectedRows[0].Cells[0].Value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.