ListView Alternate Color in C#

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 design 3. Now, have this code below. Create a function named listviewColor().
  1.   void listviewColor()
  2.         {
  3.  
  4.             //create a loop that will trigger to have the rows for items
  5.             foreach (ListViewItem item in listView1.Items)
  6.             {
  7.                 // 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
  8.                
  9.                 if ((item.Index % 2) == 0)
  10.                     // the item will have its first color white
  11.                     item.BackColor = Color.White;
  12.                 else
  13.                     // the second item will have a light blue color
  14.                     item.BackColor = Color.LightBlue;
  15.             }
  16.         }
Then call the function in the Main.
  1.         private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             // call the function
  4.             listviewColor();
  5.         }
Output: 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

Add new comment