views:

162

answers:

2

If the CTRL key is pressed and you click a selected DataGridViewRow the row is unselected. How can I stop this?

+1  A: 

That is the standard behaviour for multi-selection using [Ctrl]. Why would you break the user's expected interface? You could possibly hack around it by detecting selection changes (I'll look...)

(edit) - yes, seems to work if you hook SelectionChanged, something like:

DataGridViewRow[] lastSelectedRows = new DataGridViewRow[0];
void grid_SelectionChanged(object sender, System.EventArgs e) {
    if ((Control.ModifierKeys & Keys.Control) == Keys.Control) {
        foreach (DataGridViewRow row in lastSelectedRows) {
            if (!row.Selected) row.Selected = true;
        }            
    }
    DataGridViewSelectedRowCollection selected = grid.SelectedRows;
    lastSelectedRows = new DataGridViewRow[selected.Count];
    selected.CopyTo(lastSelectedRows, 0);
}
Marc Gravell
because I want to ensure that always a row is selected
A: 

How would you unselect something if it is accidentally selected?

leppie