Page 1 of 1

Listview check for space infront of text

Posted: Sun Jan 20, 2013 1:02 pm
by AnoPem
Hello i need help with a listview i have added some text but i want it to see what lines there are spaces before words and then color the row, is this possible if so how ?

Re: Listview check for space infront of text

Posted: Sun Jan 20, 2013 1:21 pm
by Shim
i dont know how to check if space but this will help you to check if emphty
Code: Select all
If ListView1.ListItems.Count = 0 Then
    Msgbox "ListView is empty"
Else
    Msgbox "Listview contains " & ListView1.ListItems.Count & " items"
End If

Re: Listview check for space infront of text

Posted: Sun Jan 20, 2013 1:28 pm
by comathi
This might be able to help you:
Code: Select all
Dim item As ListViewItem
For Each item In ListView1.Items
     If item.Text.Substring(0,1)=" " Then item.BackColor=Color.Red
Next

Re: Listview check for space infront of text

Posted: Sun Jan 20, 2013 1:34 pm
by AnoPem
comathi wrote:
This might be able to help you:
Code: Select all
Dim item As ListViewItem
For Each item In ListView1.Items
     If item.Text.Substring(0,1)=" " Then item.BackColor=Color.Red
Next
How would i do so its those without space that gets colored only ?

Re: Listview check for space infront of text

Posted: Sun Jan 20, 2013 2:35 pm
by comathi
Simple, just add a Not in front of the IF condition:
Code: Select all
Dim item As ListViewItem
For Each item In ListView1.Items
     If Not item.Text.Substring(0,1)=" " Then item.BackColor=Color.Red
Next