Page 1 of 1
Item ForeColor and sorting
Posted: 25 May 2010, 09:05
by Mex
Hi Timo (again:))
My question is;
When i set in CustomDraw items TexColor, how to i preserve this color when user clicks column header and all items are sorted?
Lets say i first set items forecolor to blue. (item's index=100)
After sorting this item has index 1.
Must i every time set each items color programmatically or is there any other solution?
BR;
Meelis
Re: Item ForeColor and sorting
Posted: 26 May 2010, 10:29
by TiKu
Hi,
CustomDraw cannot preserve such things, you have to set the colors and so on on each paint cycle. To make items always have the same text color even if the list view is sorted or items are inserted/removed, you could identify the items by their ID, because the ID won't change. Another approach is to use the ItemData property to store layout hints (which colors to use and so on) and read this ItemData property in CustomDraw event.
TiKu
Re: Item ForeColor and sorting
Posted: 26 May 2010, 10:50
by Mex
Hi
Currenlty i sotore color info in itemData, but i dont know what if i want to use it for other information

Maybe you can add a ForeColor property to ILIstItem

?
regards;
Meelis
Re: Item ForeColor and sorting
Posted: 26 May 2010, 15:32
by TiKu
Mex wrote:Currenlty i sotore color info in itemData, but i dont know what if i want to use it for other information

Well, you can store all these things in a complex data structure and use ItemData to store a reference to the real data (e. g. the memory address or an array index).
Mex wrote:Maybe you can add a ForeColor property to ILIstItem

?
I won't, because it's totally against how the native list view works and because text color is just one thing you can do with custom draw. If I add a per-item ForeColor property, the next one will ask why I don't add a per-item Font property, because this can be done via CustomDraw, too. Also while a per-item ForeColor property might be helpful, for you, it would be cumbersome in other situations.