I thought the only thing I had to do to disable column sorting in
VB.NET was to set datagrid.AllowSorting = False. Unfortunately this
has never worked for me. I discovered another set of code that seems
to work for 99% of the cases where I need to disable datagrid column
sorting:

Private Sub datagrid_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown
Dim pt As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = dgACE.HitTest(pt)

If hti.Type <> DataGrid.HitTestType.ColumnHeader Then
MyBase.OnMouseDown(e)
End If
End Sub

However, this code does not work when my datagrid resides on a user
control. The datagrid_MouseDown event is triggered but sorting still
occurs for the column. It's critical that I disable sorting in the
datagrid due to the other things I am trying to do with the datagrid.

I'm about ready to pull my hair out trying to figure this one out so
any suggestions on how to resolve this issue would be greatly
appreciated!

Thank you!

Joy

Re: Disable Sorting in VB.NET by bharati2u

bharati2u
Thu Dec 08 02:03:08 CST 2005


Datagrid.AllowSorting = False works if you do not have a tablestyle fo
the datagrid.

But if you have added a TableStyle you must set the
AllowSorting property of the TableStyle as this overrides the DataGrid
AllowSorting property.

DataGrid.TableStyles(0).AllowSorting = False

Hope this help

--
bharati2
-----------------------------------------------------------------------
bharati2u's Profile: http://www.highdots.com/forums/m117
View this thread: http://www.highdots.com/forums/t313546