Click here to Skip to main content
15,913,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to select automatically the lowest number in list view. I tried to compare it but it doesn't work
'Dim ct As Integer
           'For ct = 0 To .Tables(0).Rows.Count - 1
           '    Dim ls As New ListViewItem
           '    ls.Text = .Tables(0).Rows(ct).Item(0)
           '   " If ls.SubItems.Add(.Tables(0).Rows(ct).Item(2)) <= ls.SubItems.Add(.Tables(0).Rows(ct).Item(2)) Then" This code doesn't work It always says that it is invalid
           '        ls.BackColor = Color.Yellow
           '        lvpoapproveitem.Items.Add(ls)
Posted
Comments
Richard C Bishop 18-Oct-13 12:07pm    
It probably doesn't work because it is all commented out.
Kenneth Haugland 18-Oct-13 12:14pm    
:laugh: So true :-D
Richard MacCutchan 18-Oct-13 12:55pm    
What are the item types you are trying to compare? Text strings most likely so the <= operator will not work. See the String.Compare Method.

1 solution

It depends on the values present in the ListView.
I will considered that your ListView contains Integer Values.
See below code example :
VB
ListView1.MultiSelect = False
ListView1.Items(0).Selected = True
Dim _mItemMinValue As Integer = ListView1.Items(0).Text
For Each _mItem As ListViewItem In ListView1.Items
     If _mItemMinValue > Val(_mItem.Text) Then
               _mItem.Selected = True
     End If
 Next

This code automatically select ListViewItem with Lowest Integer value present in the ListView.
I hope this will help you. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900