|
-
October 20th, 2004, 04:45 AM
#1
ListViewItems background colors
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:
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 );
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.
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:
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++;
}
Any help or hints?
-
October 20th, 2004, 04:54 AM
#2
Re: ListViewItems background colors
hahahaaaaa!!! I found it!
Half of the lines were already grey and I was adding more grey lines to it without making the other white again.
This was the was to go:
Code:
int i = 0;
foreach ( ListViewItem lvi in lstFiles.Items)
{
if ( i%2 == 0 )
lvi.BackColor = Color.FromArgb ( 245 , 245 , 245 ); //VERY LIGHT GREY
else
lvi.BackColor = Color.FromArgb ( 255 , 255 , 255 ); //WHITE
i++;
}
That was a bit silly of me...
-
July 19th, 2005, 03:24 AM
#3
ListView Item loses backcolor
Hi all,
I have a list view with HideSelection set to False.I have changed the backcolors of the listview items alternately(i.e zebra effect).Now if the user clicks in the list view itself in some place where there are no items , the selected listview item loses its backcolor.However it gets restored if someother item is selected in the list view.
This is reproducible in VS2003 on an XP machine.I tried overriding the OnPaint() method so that explicitly the backcolors are assigned to the list view items.But it was of no use.So is it a bug in ListView???
It wud really help if any body could tell me as to how to go about this problem
Thanks and Regards
Amita
-
July 19th, 2005, 03:44 AM
#4
Re: ListViewItems background colors
hi ,
I am trying to do something similar to what u have done above, altertnating the backcolors of the listview item.But the problem is if i click o0n the empty space in the list view the colors go fora toss.Now if i add a new entry to the list view the colors are not restored????
-
July 19th, 2005, 04:32 AM
#5
Re: ListViewItems background colors
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
July 19th, 2005, 04:34 AM
#6
Re: ListViewItems background colors
Merged two threads... I think that's ok with you ABK?
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
July 19th, 2005, 06:02 AM
#7
Re: ListView Item loses backcolor
Hi Andy,
The code listed shows how to change the color for the subitems.But my problem is a different one.Let me explain a little more
I change the list view item backcolors(alternately)i.e control and control light colors.This works fine.My requirement is that I have a button to add a new row.So when this is done the back color for the newly added row is updated accordingly.This too works fine
But the problem is before adding a new row if the selection is on the item having controls light color, if i have clicked on an empty space in the list view the selected item loses its backcolor.It will be restored if I click on some other item in the listview.I tried explicitly updating or refreshing the list view.But it was of no use.
So is this a bug in ListView???
-
September 18th, 2007, 01:40 AM
#8
Re: ListView Item loses backcolor
hello friends,
i am also same kind of problem,
when i change a color of any row of list view, it will bw shown only when select other one and then select it back,
i have tried this with making hide selection true also,
but does get,
Do anyone has answer?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|