I think, I'm going mad with that datagrid....

I want to allow the user to select more than one row in a datagrid. By creating a new datagrid inheriting from datagrid the mulitple selection is already possible. My problem now is, how do I know, which rows are selected? Just iterating through the grid and check the "IsSelected" won't be right because sorting in that grid is possible.

Any ideas that would help me???

This is, what I've already done:


Public Class DataGridSelectMultipleRows
Inherits DataGrid

Private Const OFFSET As Integer = 5

Protected Overloads Overrides Sub OnCurrentCellChanged(ByVal e As EventArgs)
MyBase.OnCurrentCellChanged(e)
If (Control.MouseButtons <> MouseButtons.Left) Then
Dim rect As Rectangle
rect = Me.GetCellBounds(Me.CurrentCell)
Dim e1 As MouseEventArgs
e1 = New MouseEventArgs(MouseButtons.Left, 0, OFFSET, (rect.Y + OFFSET), 0)
OnMouseDown(e1)
End If
End Sub

Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
Dim hti As DataGrid.HitTestInfo
hti = Me.HitTest(e.X, e.Y)
If (hti.Type = HitTestType.Cell) Then
Dim e1 As MouseEventArgs
e1 = New MouseEventArgs(e.Button, e.Clicks, OFFSET, e.Y, e.Delta)
MyBase.OnMouseDown(e1)
Else
MyBase.OnMouseDown(e)
End If
End Sub

End Class