Re: Issue with listview alternate coloring forecolor
Originally Posted by Chris001
Once you start subclassing the Listview to change the backcolor of a row you also need subclassing to change the textcolor.
I've made a few small changes. The changes I've made are all between '///////////////////////
Thanks Chris.. Works like cream.. just like I expected.
In the example, I knew which rows would be vbred.. In the actual code, I wont be knowing as the code is quite generic. Calling SetTextColor would be difficult.
How can this be done for rows which have dynamic forecolor.
Shalll appreciate a working code like you did last....
Re: Issue with listview alternate coloring forecolor
Hi,
I am not in favour of using picturebox method. It has a few drawbacks related to our application. I'd rather stick to using subclassing.
I have found a work around for this issue using arrays but now the problem is that I have
two listviews and for both of these listviews, the forecolor gets applied, where it should be for one listview (listview1 in this case).
Please see attached sample code.. The order of listview alternate row getting applied (listview2 first and listview1 second) is the same as in my actual application. reversing it does not apply to any one..
Re: Issue with listview alternate coloring forecolor
You have two listviews and it seems that you are asking how to have Listview1 colored and not Listview2. Pardon me if I have misunderstood but to do that all you need to do is:
Re: Issue with listview alternate coloring forecolor
martin,
no, i know how to do that..the problem is that there are 2 listviews and one of them has a few rows where the fore color is blue (not black the default one)..
when i subclass to set alternate row coloring for both the listviews, the rows change to blue for both the listviews instead of the one which had a few rows as blue..
please read my earlier post and see the attachment.. this will help you understand the issue better...
Please modify my existing code and provide a sample code for a solution..
Re: Issue with listview alternate coloring forecolor
acpt, your forecolor array is shared by both listviews. Only one array, but both listviews are being subclassed.
FYI: this line in your module is wrong, you cannot change a window procedure to a string which is what OLDWNDPROC is.
Call SetWindowLong(hWnd, GWL_WNDPROC, OLDWNDPROC)
Insomnia is just a byproduct of, "It can't be done"
Re: Issue with listview alternate coloring forecolor
Originally Posted by acpt
I need to use array in WindowProc since i just know the handle of window (hwnd) when called and it needs to set the forecolor at this time..
You did not understand my hint to possibly your coloring problem. You have a 5001 item array and are setting values in it from each class used to subclass listviews. The same array is shared among every instance of the class, so if you set listtem 1 to a color in one class then set list item1 in another class to another color, the array item 1 will be overwritten by latest change. Understand?
Originally Posted by acpt
What is incorrect in 'SetWindowLong(hWnd, GWL_WNDPROC, OLDWNDPROC) ' ?
Do you understand subclassing, from start to finish? OLDWNDPROC is a string value in your module not the previous window procedure. Re-look at your code.
Edited: Suggest reconsidering arrays for listitem forecolors for several reasons
1. You really have no way of knowing how small/big to make the array, do you?
2. As mentioned above, just won't work as-is since multiple subclassed listviews share the same array
3. What happens when items are inserted/deleted, not just appended. How does that affect existing array entries?
4. What happens when items are sorted? How does that affect your array.
I think the best solution, maybe is to store the listview item's forecolor with the actual listview item. Maybe in the listitem's Tag property? Regardless, thinking this through more carefully is a recommendation.
Last edited by LaVolpe; Jul 28th, 2010 at 11:46 AM.
Insomnia is just a byproduct of, "It can't be done"