开发者

Highlight Specific Rows In ListView

开发者 https://www.devze.com 2022-12-27 00:03 出处:网络
Can anyone help开发者_JAVA技巧 me on how to highlight specific rows of ListView in vb.net?Assuming that you have it in Details mode, just make sure that FullRowSelect and MultiSelect are set to true a

Can anyone help开发者_JAVA技巧 me on how to highlight specific rows of ListView in vb.net?


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


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."

0

精彩评论

暂无评论...
验证码 换一张
取 消