Datagrid: Overload Function

ayozzhero

Well-known member
Joined
Apr 6, 2005
Messages
186
Location
Malaysia
Programming Experience
1-3
I found this code for ASP .Net but I can't implement it in VB:
Private Sub OnMyGridSort(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs)
End Sub

I cannot find the equivalent one in System.Windows.Forms...

I am trying to find a function to prevent sorting on certain colummn only. i.e the first column where it is numbered as row numbers.

Thanks.
 
For only single column it has nothing with column styles :p

Hi, ayozzhero>
You need to derive the DataGrid and override OnMouseDown.
In override, make a HitText and if the hit is on a column header that you do not want to sort, do not call the baseclass.


PHP:
 Public Class MyDataGrid 
Inherits DataGrid 
 
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs) 
Dim myPoint As New Point(e.X, e.Y) 
Dim htiTest As DataGrid.HitTestInfo = Me.HitTest(myPoint) 
If htiTest.Type = HitTestType.ColumnHeader AndAlso htiTest.Column = 1 Then 
Return 'just don't call baseclass 
End If 
MyBase.OnMouseDown(e) 
End Sub 
End Class

Cheers ;)
 
Thanks for your fast response.

For your information, what I need is... users may click anyheaders to sort... but the data in the first header remains unsorted because it contains the row number.

Currently, what I am doing is putting the row number in to an array, together with other data, then convert them to datatable. The datatable is the datasource for the datagrid.

Therefore, the first column is numbered in sequence... i.e 1 to 20. Whenever any other columns is re-sorted by user (by clicking the column header) the first column should not be re-sorted.

Sorry for not being clear... However the codes given above help me on other part of my programming

Thanks...
 
Back
Top