How do I select a complete dataGridView Row when the user clicks a cell of that row?

后端 未结 6 1012
梦毁少年i
梦毁少年i 2020-12-14 14:01

I have a dataGridView and I need that when the user clicks on any cell the whole row that contains this cell is selected too. (it has multiselect disbaled) I t

6条回答
  •  猫巷女王i
    2020-12-14 14:33

    //class to store ID (Pri. Key) value of selected row from DataGridView
    public class Variables
    {
       public static string StudentID;
    }                                  
    
    //This is the event call on cell click of the DataGridView
    private void dataGridViewDisplay_CellClick(object sender, DataGridViewCellEventArgs e)
    {
       Variables.StudentID =this.dataGridViewDisplay.CurrentRow.Cells[0].Value.ToString();
    //textBoxName is my form field where I set the value of Name Column from the Selected row from my DataGridView 
    
       textBoxName.Text = this.dataGridViewDisplay.CurrentRow.Cells[1].Value.ToString();
    
       dateTimePickerDOB.Value = Convert.ToDateTime(this.dataGridViewDisplay.CurrentRow.Cells[2].Value.ToString());
    }
    

    Take a look at My DataGridView

提交回复
热议问题