Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change color of selected row in listview control?

Status
Not open for further replies.

JawwadLone

Programmer
Mar 17, 2004
57
PK
I am using ListView Control in Visual Basic 6.0. I want to change the color of selected row in listview. I have used this code to change the color of selected listview item

ListView1.SelectedItem.ForeColor = vbGreen

But this code only changes the color of listview item. I want to change the color of complete row. Is it possible or not?

Another thing I want to know is, I am using a textbox to make entries in listview control. My textbox is placed beside the listview control. Is there any way i can move my textbox on anyparticular subitem in listview control and set the size of the textbox according to that particular subitem? I would be very thankfull, if any one solve my problem.
I am using this code in KeyDown event of textbox

If (KeyCode >= 48 And KeyCode <= 56) Or KeyCode = 45 Then Exit Sub

If KeyCode = 13 Or KeyCode = 40 Then 'Down Arrow
ls.SubItems(2) = Val(Text1.Text)
If rec < lsCount Then
ls.ForeColor = vbBlack
rec = rec + 1
Set ls = ListView1.ListItems.Item(rec)
ls.ForeColor = vbGreen
Text1.Text = ls.SubItems(2)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
ElseIf KeyCode = 38 Then 'Up Arrow
ls.SubItems(2) = Val(Text1.Text)
If rec > 1 Then
ls.ForeColor = vbBlack
rec = rec - 1
Set ls = ListView1.ListItems.Item(rec)
ls.ForeColor = vbGreen
Text1.Text = ls.SubItems(2)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End If
 
To colour listview subitems use:[tt]

ListView1.SelectedItem.ListSubItems(1).ForeColor = vbRed[/tt]

and loop through the subitems collection.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top