How to get values from selected row in DataGrid for Windows Form Application?

后端 未结 2 1486
无人及你
无人及你 2020-12-10 03:18

Title is pretty self-explanatory. I\'ve got a DataGrid for a Windows Form Application, and I want to be able to store the values of a selected row. What is the easiest way

相关标签:
2条回答
  • 2020-12-10 03:28

    You could just use

    DataGridView1.CurrentRow.Cells["ColumnName"].Value
    
    0 讨论(0)
  • 2020-12-10 03:37

    Description

    Assuming i understand your question.

    You can get the selected row using the DataGridView.SelectedRows Collection. If your DataGridView allows only one selected, have a look at my sample.

    DataGridView.SelectedRows Gets the collection of rows selected by the user.

    Sample

    if (dataGridView1.SelectedRows.Count != 0)
    {
        DataGridViewRow row = this.dataGridView1.SelectedRows[0];
        row.Cells["ColumnName"].Value
    }
    

    More Information

    • MSDN - DataGridView.SelectedRows Property
    0 讨论(0)
提交回复
热议问题