Select the row in the DataGrid

I have the datagrid and I want to have alwayes one row selected. If I click on the column header none rows get selected (even if I had one row selected).  I tried to put 
myDataGrid.Select(0) in the  myDataGrid_MouseUP, but it does not work. Maybe somebody knowes, is there way to make the row selected when a user clicks on the column header


Answer this question

Select the row in the DataGrid

  • taoo tha mastah

    You could create a class that inherits from DataGrid.  Then override OnMouseDown in your derived class

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
            Dim pt As New System.Drawing.Point(e.X, e.Y)
            Dim hti As DataGrid.HitTestInfo = Me.HitTest(pt)
            If hti.Type = DataGrid.HitTestType.ColumnHeader Then
                Me.Select(0)
                Return
            End If
            MyBase.OnMouseDown(e)
    End Sub

    Hope this helps

  • Select the row in the DataGrid