mauro_camb

Hi,

I'm trying to figure how if it's possible to completely deselect rows, including the arrow symbol in the rowheader cell.

The reason I am trying to do this is because with multiple selections (eg. using CTRL key) the user can select multiple rows, but they can also deselect previous selections.

Example:
- Select first 3 rows with CTRL key
- Deselect 3rd row with CTRL key. The SelectedRows collection correctly reflects the change, and now contains only the first 2 rows. Also, the CurrentRow.Selected = false for the third row
- But the RowHeader arrow is still on the third row, which is now no longer selected
- What I would ideally like is to set the new CurrentRow to be the second row, and the RowHeader to be updated accordingly

I have tried the following:

DataGridViewSelectedRowCollection selRows = _dataGrid.SelectedRows;
bool selected = _currentRow.Selected;
if (selRows.Count > 0 && !selected)
{
//Get index of last row in selRows collection
RowIndex = selRows[selRows.Count - 1].Index;

//The following call results in selRows being cleared and only 1 row being
//selected
_dataGrid.CurrentCell = _dataGrid.Rows[RowIndex].Cells[0];
}

but it does not do what I need.

Any suggestions would be greatly appreciated.

Thanks

Mauro Ciaccio




Re: Windows Forms Data Controls and Databinding How to deselect the DataGridView row header

vkh75

Private Sub dgv_SelectionChanged(...) Handles dgv.SelectionChanged

If dgv.Focused = True AndAlso dgv.CurrentRow.Selected = False Then

Dim r As DataGridViewSelectedRowCollection = dgv.SelectedRows

If r.Count > 0 Then

dgv.CurrentCell = r(0).Cells(0)

For Each row As DataGridViewRow In r

row.Selected = True

Next

End If

End If

End Sub






Re: Windows Forms Data Controls and Databinding How to deselect the DataGridView row header

mauro_camb

Hi,

thanks for that. It should do most of what I need, though there is the added complexity of having to determine at runtime which is the current cell. Selecting r(0).Cells(0) is not satisfactory if I want to move to the row closest to the one I just unselected.

M




Re: Windows Forms Data Controls and Databinding How to deselect the DataGridView row header

vkh75

Sorry, I don't get what you mean. What cell do you want to get current after you deselect a row