如何在C#Windows应用程序中获取网格的列值?
如何在C#Windows应用程序中获取网格的列值 当我点击单元格时,它应该会得到列值如何在C#Windows应用程序中获取网格的列值?,c#,windows,datagrid,C#,Windows,Datagrid,如何在C#Windows应用程序中获取网格的列值 当我点击单元格时,它应该会得到列值 private void gridAgentDetails_Click(object sender, EventArgs e) { for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++) { string str = gridAgentDetails.Text; } } private vo
private void gridAgentDetails_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++)
{
string str = gridAgentDetails.Text;
}
}
private void gridAgentDetails\u单击(对象发送方,事件参数e)
{
对于(int i=0;i
使用DataGridView.CurrentCell.Value
:
String result = this.gridviewAgentDetails.CurrentCell.Value.ToString();
获取当前活动的单元格
获取与此单元格关联的值。要获取所选单元格的值,请执行以下代码
int CNo = datagrid.CurrentCellAddress.Y;
int StNum = (int)datagrid.Rows[CNo].Cells[0].Value;
string StName = (string)datagrid.Rows[CNo].Cells[1].Value;
int MrksSecured = (int)datagrid.Rows[CNo].Cells[2].Value;
尝试此eventHandler:[我尝试了此方法,得到了结果]
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
int colIndex = e.ColumnIndex;
MessageBox.Show(dataGridView1[colIndex, rowIndex].Value.ToString());
}
由于您评论说您使用的是DataGrid,因此这是一个WPF应用程序,而不是表单应用程序 WPF DataGrid控件是数据的可视化表示,不能直接从DataGrid中读取特定单元格,因此不能在DataGrid上选择特定行或列,除非将其绑定到数据源 DataGrid设计用于数据表。请参阅以了解如何将数据网格绑定到数据表
然后,要读取DataGrid中的特定单元格值,您可以改为读取DataTable(例如,
dataTable1[RowNumber][ColumnName]
其中RowNumber是一个int,ColumnName是一个字符串。我要求的是datagrid而不是gridview。我要求的是datagrid而不是gridview。阅读本文一次,了解datagrid和gridview之间的区别。你问的是关于System.Windows.Forms.DataGridView
??@Akaram,我认为rams在WPF中使用datagrid控件。这不是一个Form应用程序。