Results 1 to 12 of 12

Thread: Issue with listview alternate coloring forecolor

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    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....
    Attached Files Attached Files

  2. #2
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    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 '///////////////////////
    Attached Files Attached Files

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    Re: Issue with listview alternate coloring forecolor

    Quote Originally Posted by Chris001 View Post
    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....


  5. #5
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: Issue with listview alternate coloring forecolor

    Hi acpt,

    In Chris's example, just pass any Forecolor..

    vb Code:
    1. SetTextColor ListView1, 7, vbBlue
    2. SetTextColor ListView1, 8, RGB(100, 250, 200)
    3. SetTextColor ListView1, 9, &H80FFFF

    Regards
    Veena

  6. #6

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    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,
    Attached Files Attached Files

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    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..

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    12

    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)
    ' ?

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Issue with listview alternate coloring forecolor

    Quote Originally Posted by acpt View Post
    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 View Post
    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width