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

后端 未结 2 1500
无人及你
无人及你 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: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

提交回复
热议问题