I have a windows form in which we have a DataGridView. The property of that is cell select and I have a ContextMenustrip in which there is a menu named select all when select all is clicked it should change the property of DataGridView of the selected cell to the FullRowSelect and the selection should be on the same row which I have clicked. the problem is when i click on a cell the default property is cell select and when I click on select all of the ContextMenustrip the selected cell is not selected and I have to re-select that row I want that when the form opens and when i click on particular cell and when i click on select all of the ContextMenustrip is clicked then the same row should be selected on which I have clicked the cell previously this is my code.
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
If I’m reading your question correctly, you want to select the entire row when the “Select All” option of a context menu is clicked. If that is correct, you might try:
or
You will need to remove the following line first:
The above line will put the DataGridView into full-row select mode, in which the SelectedCells property will not be used, and you will then see the following exception when you click the Select All option in your context menu.
The entire function should look like this:
Note that the user will need to (left) click the cell whose row they want to select before right-clicking to bring up the context menu. Otherwise, the selection will not change, and the previously-selected cell’s row will be selected.