views:

262

answers:

2

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

A: 

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
ho1
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?
Mark
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.
ho1
A: 

I believe you can catch the ItemDataBoundEvent and set the css class on your rows. This example shows the concepts:

http://msdn.microsoft.com/en-us/library/bb350797(v=VS.100).aspx

If you make your row containers runat="server" and give them an ID, then you should be able to get them with FindControl.

The classes you add to your row container (tr, div, etc) will reflect your states (error, committed, etc). Then, you can apply whatever styling (background-color) you want to those classes in your stylesheet.

Remember to concatenate the new class to the css class property, in case another class is already there, like "Selected."

BJ Safdie