|
|
|
This is one I discovered after banging my head against the wall for a few hours trying to get a list view control to sort numbers correctly. When trying to create a list view control in report mode that would allow a user to quickly sort by a text listing (in this case a column of state abbreviations) or sort by counts for each state, I ran into a data type issue that is not addressed with this control. The problem is that when a numeric column is entered as the sort key, the control treats it as text. To overcome this problem, I created a third column and set its width to zero so it would not be visible at run time. I then assigned the count with several leading zero's to this column.
i.e. xitem.SubItems(3) = Right("00000000" & count, 8) created 00000001 from 1 00000057 from 57 00331562 from 331562
The leading zero's on these numbers will cause them to sort correctly as text. When the user clicked on the visible column, I just switched the column index to the hidden one. |
Click here to copy the following block | Private Sub lvwDisp_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader) lvwDisp.SortKey = ColumnHeader.Index - 1 If lvwDisp.SortKey = 1 Then lvwDisp.SortKey = 3 lvwDisp.SortOrder = (lvwDisp.SortOrder - 1) * -1 lvwDisp.Sorted = True End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|