0
votes

Don't ask why, but I need a way to prevent the user from entering a cell in the 'new' datagridview row WHILE they've got multiple rows selected.

Currently, the cell in the first column of the row that the mouse is hovering over during the click and drag is being selected. If you click on the cell, then the rows aren't selected anymore, so you can't use any cell click events or anything.

Any suggestions are welcome.

P.S. don't try editing the currentcell from the selectionchanged event, already tried that!

Thanks,

Isaac

2

2 Answers

0
votes

I have an idea that the DataGridView control has a RowState property. When your row is selected, check the state. I'm not sure what the states are (if I'm even in the ballpark) ... anyway, you may be able to check that route.

I'm looking for more info ...

Okay ... think I found a decent way to do this:

void DataGridView1_RowsAdded (object sender, DataGridViewRowsAddedEventArgs e)
{
    currentNewRow = e.RowIndex;
}

void DataGridView1_CellMouseClick(Object sender, DataGridViewCellMouseEventArgs e)
{
    if (e.RowIndex == currentNewRow)
    {
        // don't add to Selection
    }
} 
0
votes

Use CellStateChanged event:

private void dataGridView_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e) {
            if (e.Cell.OwningRow.IsNewRow && dataGridView.SelectedRows.Count > 1)
                e.Cell.Selected = false;
        }