Monday, October 17

VB.NET: Listview control (Backcolor and Alternate row color)

This is my first article for VB.NET. This techniques will help our user to see data clearly and more presentable.

ListView control allows you to display a list of items with item text and, optionally, an icon to identify the type of item. The ListView control can be used to display information from an application, a database, or a text file. It provides a large number of properties that provide flexibility in appearance and behavior(http://social.msdn.microsoft.com/Search/en-us?query=listview&x=0&y=0).



Well basically,we can change our listview background directly to the property window just select the listview then change the backColor, choose the color you want. But if you want to code it just simply add this line:





ListViewName.BackColor=Color.ColorYouWant

                                                                                                                             
If we want to have alternate rows color we can use this codes



After you populate or retrieve your data put the codes next to it to have an alternate row color. Select the color you want.




Output:



I hope you understand it and helped you!




"'Love the Lord your God with all your heart and with all your soul and with all your strength and with all your mind'; and, 'Love your neighbor as yourself.'"

Luke 10:27


To GOD all the Glory
                                                 

10 comments:

  1. Can't seem to raise ColorYouWant on my intellisense :-)
    Thanks

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. You save my project ... thanks for this ... more power bro ...

    ReplyDelete
  4. This works unless there's an uneven amount of fields, you will miss one if there are try using the following instead :


    For i = 0 To listview1.Items.Count - 1
    If isEven(i) Then listview1.Items(i).BackColor = Color.White Else listview1.Items(i).BackColor = Color.AliceBlue
    Next i

    It uses this simple function :

    Private Function isEven(numToCheck As Integer) As Boolean
    Return (numToCheck And 1) = 0
    End Function




    ReplyDelete
  5. lo he probado en load, en drawitem y no funciona, acá no se especifica como usar esto, tengo que crear una nueva clase o que?

    ReplyDelete