我已经调查过了,但我无法找到明确的答案
- 允许用户从表单的数据 GridView 中选择数据。
- 如何在用户选择了他们需要的信息后点击用户表单上的按钮以编程方式完成此操作
使用 C#
最佳答案
要在 Windows 窗体中启用整行选择,您可以这样做
this.dataGridView1.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.MultiSelect = false;
如果你想得到选中的行,你可以这样做:
private void dataGridView1_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
var rowIndex = e.RowIndex;
var currentRow = dataGridView1.Rows[rowIndex];
var currentCellValue = dataGridView1.Rows[rowIndex].Cells[e.ColumnIndex].Value.ToString();
}
关于c# - 从数据 GridView 中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12744111/