1 Previous Next 

DataGrid: Prevent Row And Column Resize


To prevent the user from resizing the rows or columns of a datagrid you need to create a new datagrid. To create a new grid create a class that inherits from datagrid. To prevent the resize prevent the OnMouseDown and OnMouseMove messages from firing when the user is at the resize spot.

Be aware this is a Tip for a WindowsForms DataGrid not a DataGridView




Public Class NoResizeGrid
    Inherits DataGrid


    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

        If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type = DataGrid.HitTestType.RowResize Then

            Return 'no baseclass call

        End If

        MyBase.OnMouseDown(e)
    End Sub

    Public Sub New()

    End Sub

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

        If hti.Type = DataGrid.HitTestType.ColumnResize Or hti.Type = DataGrid.HitTestType.RowResize Then

            Return 'no baseclass call

        End If

        MyBase.OnMouseMove(e)
    End Sub


End Class



1 Previous Next