Friday, February 15, 2008

Sorting with HeadClick Event on Datagrid

Sometime we has a datagrid with the large fields. example in employee table, we have fields likes: NIK, name, address, town, birthday, joint date, marital status, and so on.
usually we just sorting on NIK, but sometime we need sorting the table based on name or joint date or anything on that table.

how we can make the datagrid flexible on sorting? its simple. we can use event "HeadClick" on datagrid.


the idea is when we click the header of datagrid, the data on datagrid will be sort by that header name.

here the simple code I make to show how to use that HeadClick Event:

Private Sub DataGrid1_DblClick()
On Error GoTo handle
With rsLoadData
Text_nik = Trim(.Fields(0))
Text_nmKary = Trim(.Fields(1))
Text_Alamat = Trim(.Fields(2))
text_tgllahir.Value = .Fields(3)
Text_kdStatus = Trim(.Fields(4))
Text_kdMarital = Trim(.Fields(5))
End With
SSTab1.Tab = 0
Exit Sub
handle:
MsgBox Err.Description
End Sub

Private Sub DataGrid1_HeadClick(ByVal ColIndex As Integer)
On Error GoTo handle
rsLoadData.Sort = "[" & DataGrid1.Columns(ColIndex).Caption & "] ASC"
Exit Sub
handle:
MsgBox Err.Description
End Sub




0 comments:

Google

Microsoft News for ADO .NET:

Our Email Address:

blog.programming@gmail.com