ListView Alternate Color in C#
Submitted by donbermoy on Monday, October 19, 2015 - 09:24.
In this tutorial, I will teach you how to create a program that has an alternate color in C#.
So, now let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application.
2. Add only one ListView in your Form. Make sure that you put the ListView a column name and items inside the ListView
3. Now, have this code below.
Create a function named listviewColor().
Then call the function in the Main.
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

- void listviewColor()
- {
- //create a loop that will trigger to have the rows for items
- foreach (ListViewItem item in listView1.Items)
- {
- // to have the alternate color we will have the index of that items to have its remainder that will be equal only to 0 or 1
- if ((item.Index % 2) == 0)
- // the item will have its first color white
- item.BackColor = Color.White;
- else
- // the second item will have a light blue color
- item.BackColor = Color.LightBlue;
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- // call the function
- listviewColor();
- }

Add new comment
- 247 views