1 Attachment(s)
Issue with listview alternate coloring forecolor
hi,
In Vb 6.0, I am using WindowProc to set alternate row coloring of listview
In this listview fore color of a few rows are set to blue.
After the alternate row coloring is applied, the forecolor of these rows revert back to the
default black color.
How do I retain the fore color of these rows to blue and also get the listview alternate row coloring ?
Attached sample code..
Shall await a quick response....
1 Attachment(s)
Re: Issue with listview alternate coloring forecolor
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 '///////////////////////
Re: Issue with listview alternate coloring forecolor
If you'd like to do alternate back color (the greenbar look) then try this. It has no subclassing.
Edit : Removed zip file. See post #6.
Re: Issue with listview alternate coloring forecolor
Quote:
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 '///////////////////////
:wave:
Thanks Chris.. Works like cream.. just like I expected.:thumb:
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....
:wave:
Re: Issue with listview alternate coloring forecolor
Hi acpt,
In Chris's example, just pass any Forecolor..
vb Code:
SetTextColor ListView1, 7, vbBlue
SetTextColor ListView1, 8, RGB(100, 250, 200)
SetTextColor ListView1, 9, &H80FFFF
Regards
Veena
1 Attachment(s)
Re: Issue with listview alternate coloring forecolor
It was pointed out to me that my zip file was incomplete so here is a new one. I also eliminated some extraneous stuff.
1 Attachment(s)
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..
Regards,
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:
' x.SetListViewAlternateColor ListView2
x.SetListViewAlternateColor ListView1
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)
Re: Issue with listview alternate coloring forecolor
LaVolpe,
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..
What is incorrect in 'SetWindowLong(hWnd, GWL_WNDPROC, OLDWNDPROC)
' ?
Re: Issue with listview alternate coloring forecolor
Quote:
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?
Quote:
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.