How to get column value of grid in C# Windows application?

前端 未结 4 1516
庸人自扰
庸人自扰 2021-02-11 01:36

How to get column value of grid in C# Windows application?

When I clicked on the cell, at that time it should get column values.

private void gridAgentD         


        
4条回答
  •  暖寄归人
    2021-02-11 01:52

    Since you comment saying you're using DataGrid, this is a WPF application, not a Form application.

    WPF DataGrid Control is visual representation of data, you cannot read a specific cell directly out of a DataGrid, Hence you cannot select a specific row or column on a DataGrid, unless you bind it to a data source.

    DataGrid is designed to use with DataTable. See this link to see how DataGrid is binded to DataTable.

    Then, to read a specific cell value in DataGrid, you would read the DataTable instead (e.g. dataTable1[RowNumber][ColumnName] where RowNumber is an int, and ColumnName is a string.

提交回复
热议问题