good day everyone, im currently using vs.net 2003
my problem is that i want to sort items in listview by date (mm dd, yyyy) format and sort by a button not in the column :?:
please help me.. thanks in advance!
thanks for the quick reply adatapost, but none of those threads help me..
actually i already have a code but it's only working with number and string not in a date(e.g October 13, 1983)
here is my code
Public Sub SortNumberListView(ByVal LstView As ListView, ByVal SortCol As Int16, ByVal Ascending As Boolean)
Dim h As Int16
Dim o As Int16
Dim y As Int16
Dim TempVarhoy As String
With LstView
For h = 0 To .Items.Count - 1
For o = h + 1 To .Items.Count - 1
If Ascending = True Then
If Val(.Items(h).SubItems(SortCol).Text) > Val(.Items(o).SubItems(SortCol).Text) Then
For y = 0 To .Columns.Count - 1
TempVarhoy = .Items(h).SubItems(y).Text
.Items(h).SubItems(y).Text = .Items(o).SubItems(y).Text
.Items(o).SubItems(y).Text = TempVarhoy
Next
End If
Else
If Val(.Items(h).SubItems(SortCol).Text) < Val(.Items(o).SubItems(SortCol).Text) Then
For y = 0 To .Columns.Count - 1
TempVarhoy = .Items(h).SubItems(y).Text
.Items(h).SubItems(y).Text = .Items(o).SubItems(y).Text
.Items(o).SubItems(y).Text = TempVarhoy
Next
End If
End If
Next
Next
End With
End Sub
'here's my button code
Private Sub cmdbday_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbday.Click
Try
If Not cbomfrom.SelectedIndex = 0 Then
empsrchd.Open("SELECT * FROM tblemployee WHERE DOBm Like '" & cbomfrom.SelectedItem & "'AND role = '" & "active" & "'", db)
empsrchd.MoveFirst()
Dim bday As ListViewItem
Do While Not empsrchd.EOF
bday = ListView1.Items.Add(empsrchd.Fields("firstname").Value, 0)
bday.SubItems.Add(empsrchd.Fields("lastname").Value)
bday.SubItems.Add(empsrchd.Fields("DOBm").Value)
bday.SubItems.Add(empsrchd.Fields("DOBd").Value)
bday.SubItems.Add(empsrchd.Fields("branchme").Value)
empsrchd.MoveNext()
Loop
cmdprintbday.Visible = True
empsrchd.Close()
Static Ascend As Boolean
If Ascend = False Then
Ascend = True
Else
Ascend = False
End If
SortNumberListView(ListView1, 3, Ascend)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
the above code is for number sorting, how can i sort for whole date?
please help me i really need it
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.