Getting data from selected datagridview row and which event?

后端 未结 5 1369
眼角桃花
眼角桃花 2020-12-08 06:53

I have a DataGridView (Selectionmode: FullRowSelect) on a windows form along with some textboxes, so what i want to do is that whenever a user selects a row(click or double_

5条回答
  •  渐次进展
    2020-12-08 07:17

    Simple solution would be as below. This is improvement of solution from vale.

    private void dgMapTable_SelectionChanged(object sender, EventArgs e) 
    {
        int active_map=0;
        if(dgMapTable.SelectedRows.Count>0)
            active_map = dgMapTable.SelectedRows[0].Index;
        // User code if required Process_ROW(active_map);
    }
    

    Note for other reader, for above code to work FullRowSelect selection mode for datagridview should be used. You may extend this to give message if more than two rows selected.

提交回复
热议问题