Im using this code !

cmd = New OleDbCommand("select * from RoomTypeA", con)
conreader = cmd.ExecuteReader

Do While conreader.Read

If conreader.Item("TimeEnd") = Me.TextBox6.Text Then

Me.RTypeListA.Items(0).Selected = True

End If


i want to select the item in listview that has the same TimeEnd with textbox6..
this code works properly but the onet that has been select is the top item in list but
the item that should be selected is on the the third line....

please help me to solve this....

Recommended Answers

All 7 Replies

See if this helps to locate and select item in ListView.

For Each itm As ListViewItem In ListView1.Items '// loop thru all items.
            If itm.Text = TextBox1.Text Then
                itm.Selected = True '// select.
                itm.EnsureVisible() '// make sure item is visible.
                Exit For '// exit loop since item located.
            End If

To codeorder :

I tried it but it wont work ...
please help me ... ill appreciate it much...

Does your ListView have Columns and if so, which column would Me.TextBox6.Text have to be compared to?

yes it have coluomns ...

ahmm. in list it starts counting in 0 so the column would be at 5..

Using my previously posted code, replace If itm.Text = TextBox1.Text Then with If itm.SubItems(6).Text = TextBox1.Text Then , or whichever .SubItems(#) is related to the specific column.

but still it wont work ... i've tried as you instructed.

hehe ... now i got it .. its just there is a wrong part in your code
but it really helps me a lot... thanks code order..

using your code

For Each itm As ListViewItem In ListView1.Items
If itm.Text = TextBox1.Text Then
itm.Selected = True
Exit For ' I remove this part in the code
End If

i have just remove Exit For ...
as what i have understand after it reads it exits directly ...
so in order to let it read until the end of data ...
i remove the Exit For

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.