Highlight Specific Rows In ListView

11,922

Assuming that you have it in Details mode, just make sure that FullRowSelect and MultiSelect are set to true and then just set the Selected property on the Items (rows) that you want to true.
Assuming that you have a ListView called ListView1 the following should work:

ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)  
ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)  
ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2})  

ListView1.View = View.Details  
ListView1.MultiSelect = True  
ListView1.FullRowSelect = True  
ColumnHeader1.Width = -2  
ColumnHeader2.Width = -2  

For index As Integer = 0 To 3  
    ListView1.Items.Add("Number" & index.ToString()).SubItems.Add("text")  
Next  
ListView1.Items(1).Selected = True  
ListView1.Items(3).Selected = True
Share:
11,922
Mark
Author by

Mark

Updated on June 22, 2022

Comments

  • Mark
    Mark almost 2 years

    Can anyone help me on how to highlight specific rows of ListView in vb.net?

  • Mark
    Mark about 14 years
    Thanks to this response. anyway, what I mean in highlighting is there was a specific color code that may highlight the rows in listview. It's like a legend, Example all rows highlighted in red was committed an error, all rows highlighted as yellow was committed a warning. Have you any idea on how to do that?
  • Hans Olsson
    Hans Olsson about 14 years
    Not sure if I understand but you can set the BackColor and ForeColor of the Items and SubItems in the ListView. So just find the Item (row) you want and set it and it's subitems BackColor to any colour you want.