How do I get a DataRow from a row in a DataGridView

后端 未结 4 585
长情又很酷
长情又很酷 2020-12-13 09:05

I\'m using a databound Windows Forms DataGridView. how do I go from a user selected row in the DataGridView to the DataRow of the

相关标签:
4条回答
  • 2020-12-13 09:45
    DataRow row = ((DataRowView)DataGridViewRow.DataBoundItem).Row
    

    Assuming you've bound an ordinary DataTable.

    MyTypedDataRow row = (MyTypedDataRow)((DataRowView)DataGridViewRow.DataBoundItem).Row
    

    Assuming you've bound a typed datatable.

    See the article on MSDN for more information.

    0 讨论(0)
  • 2020-12-13 09:49

    In a DataGridViewRow is a property called DataBoundItem of type object.

    This will contain a DataRowView (for certainty you can check this)

    0 讨论(0)
  • 2020-12-13 09:52

    In Visual Studio 2017 .NET 4.5, I had success with

     var row = (DataRowView) e.Row.DataItem;
    
    0 讨论(0)
  • 2020-12-13 10:00
    DataTable table = grdMyGrid.DataSource as DataTable;
    DataRow row = table.NewRow();
    row = ((DataRowView)grdMyGrid.SelectedRows[0].DataBoundItem).Row;
    
    0 讨论(0)
提交回复
热议问题