Hi,
I create file list and place it in a listview. When I'm adding ListViewItems to the list, I make one line white background, next line grey for easy viewing. I use this code to do so:
Works like a charm! But then I want to sort this list and after the sort, the coloring is (of course) completely whack. I get several lines of grey or white after another.Code:ListViewItem l_lviFileData = new ListViewItem ( new string [] { fi.Name.ToString(), fi.LastWriteTime.ToString() } ); if ( l_iAddedItems%2 == 0 ) l_lviFileData.BackColor = Color.FromArgb ( 245 , 245 , 245 ); //VERY LIGHT GREY p_lvListview.Items.Add ( l_lviFileData );
Does anyone has a good idea how to do this? I was thinking about a loop after the sort that would repeat the background coloring but it didn't work.
This, I tried:
Any help or hints?Code:int i = 0; foreach ( ListViewItem lvi in lstFiles.Items) { lstFiles.Items.RemoveAt(i); if ( i%2 == 0 ) lvi.BackColor = Color.FromArgb ( 245 , 245 , 245 ); //VERY LIGHT GREY lstFiles.Items.Insert(i , lvi); i++; }




Reply With Quote