Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing Column Width Changes in a datagrid 1

Status
Not open for further replies.

Elena

Technical User
Oct 20, 2000
112
US
Anyone know how to prevent column width changes in a datagrid? I know there is a WidthChanged event for the ColumnStyles but I don't know how to use it. When I try to make a subroutine to handle it, it only gives me the child objects of the form. I can't even get to the columnstyles.

Thanks,
Elena
 
You can achieve this by overriding OnMouseMove event and not calling the baseclass if the point is on the columnsizing border.


Public Class MyDataGrid

Inherits DataGrid

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 Then

Return 'no baseclass call

End If

MyBase.OnMouseMove(e)

End Sub

End Class



 
you'll have to use the above code in override of OnMouseDown event.

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 Then

Return 'no baseclass call

End If

MyBase.OnMouseDown(e)

End Sub



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top