Results 1 to 14 of 14

Thread: [RESOLVED] how do i color each listsubitems?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Resolved [RESOLVED] how do i color each listsubitems?

    hey
    is there a way to color each listsubitem row?
    e.x
    first row name is salsa and the color is red
    second row is mambo the color is green
    this is the code i am using to load from the database
    Code:
        Dim Rs As New ADODB.Recordset
        Rs.Open "Select * From PriceList Order By PriceName", CN
        LsVw.ListItems.clear
        Do While Not Rs.EOF
        Set itm = LsVw.ListItems.Add(, , Rs!PriceName, 1)
            itm.SubItems(1) = Rs!PriceColor ' Here i want the color
        Rs.MoveNext
        Loop
        Rs.Close
    of course i need to loop to get for each name its color
    appreciate any help
    salsa
    Last edited by salsa31; May 24th, 2017 at 03:14 AM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: how do i color each listsubitems?


  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: how do i color each listsubitems?

    Quote Originally Posted by Arnoutdv View Post
    hey
    i saw this but its not helping me that much
    because i have individuales colors that i save

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: how do i color each listsubitems?

    I don't understand what you mean.
    It's a routine so set the backcolor of a single listview row.
    What doesn't work for you?

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: how do i color each listsubitems?

    Quote Originally Posted by Arnoutdv View Post
    I don't understand what you mean.
    It's a routine so set the backcolor of a single listview row.
    What doesn't work for you?
    too complicated for me

  6. #6

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: how do i color each listsubitems?

    well i played a little with the code and this is the result i got
    Code:
    Private HairColor(35) As Long
        HairColor(1) = RGB(255, 148, 132)
        HairColor(2) = RGB(132, 156, 231)
        HairColor(3) = RGB(165, 222, 99)
        HairColor(4) = RGB(231, 231, 214)
        HairColor(5) = RGB(255, 181, 115)
        HairColor(6) = RGB(132, 239, 247)
        HairColor(7) = RGB(214, 206, 132)
        HairColor(8) = RGB(198, 165, 247)
        HairColor(9) = RGB(165, 206, 198)
        HairColor(10) = RGB(255, 231, 115)
        HairColor(11) = vbRed
        HairColor(12) = RGB(75, 0, 130)
        HairColor(13) = RGB(0, 255, 255)
        HairColor(14) = RGB(113, 198, 113)
        HairColor(15) = RGB(139, 35, 35)
        HairColor(16) = RGB(227, 207, 87)
        HairColor(17) = RGB(255, 255, 0)
        HairColor(18) = RGB(99, 184, 255)
        HairColor(19) = RGB(165, 42, 42)
        HairColor(20) = RGB(65, 105, 225)
        HairColor(21) = RGB(255, 239, 213)
        HairColor(22) = vbBlack
        HairColor(23) = RGB(255, 182, 193)
        HairColor(24) = RGB(205, 92, 92)
        HairColor(25) = RGB(240, 128, 128)
        HairColor(26) = RGB(255, 127, 80)
        HairColor(27) = RGB(128, 128, 0)
        HairColor(28) = RGB(72, 61, 139)
        HairColor(29) = RGB(0, 128, 128)
        HairColor(30) = RGB(216, 191, 216)
        HairColor(31) = RGB(219, 112, 147)
        HairColor(32) = RGB(25, 25, 112)
        HairColor(33) = RGB(70, 130, 180)
        HairColor(34) = RGB(255, 0, 255)
        HairColor(35) = vbBlue
    Code:
        Dim RsH As New ADODB.Recordset
        RsH.Open "SELECT * from ColorDiary ORDER BY TreatName", CN
        LsVw.ListItems.clear
        Do While Not RsH.EOF
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
            itm.SubItems(1) = HairColor(RsH!UserColorNumber)
            itm.ListSubItems(1).ForeColor = HairColor(RsH!UserColorNumber)
            RsH.MoveNext
        Loop
        RsH.Close
    Name:  Untitled.jpg
Views: 237
Size:  13.2 KB

  7. #7
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: how do i color each listsubitems?

    Looks fine, doesn't it?

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: how do i color each listsubitems?

    Purple, green and blue hair? Guess Spain has some weirdos also!

    Is that the result you wanted...like A says, looks fine, except --

    What happens if the backcolor of your control (looks like white) and one or more of your customers has/have white hair (kinda like mine is getting)...the forecolor would be white and you would not be able to see the number. And variants of grey might also not be very visible.

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: how do i color each listsubitems?

    Quote Originally Posted by Arnoutdv View Post
    Looks fine, doesn't it?
    instead of the number i want it to be colored

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: how do i color each listsubitems?

    Don't assign a text and set the .BackColor
    Code:
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
            itm.SubItems(1) = ""
            itm.ListSubItems(1).BackColor = HairColor(RsH!UserColorNumber)
            RsH.MoveNext
        Loop
    Or if you need to retrieve the actual UserColorNumber later from the ListView then you can do this:
    Code:
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
            itm.SubItems(1) = RsH!UserColorNumber
            itm.ListSubItems(1).ForeColor = HairColor(RsH!UserColorNumber)
            itm.ListSubItems(1).BackColor = HairColor(RsH!UserColorNumber)
            RsH.MoveNext
        Loop

  11. #11

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: how do i color each listsubitems?

    Quote Originally Posted by Arnoutdv View Post
    Don't assign a text and set the .BackColor
    Code:
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
            itm.SubItems(1) = ""
            itm.ListSubItems(1).BackColor = HairColor(RsH!UserColorNumber)
            RsH.MoveNext
        Loop
    Or if you need to retrieve the actual UserColorNumber later from the ListView then you can do this:
    Code:
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
            itm.SubItems(1) = RsH!UserColorNumber
            itm.ListSubItems(1).ForeColor = HairColor(RsH!UserColorNumber)
            itm.ListSubItems(1).BackColor = HairColor(RsH!UserColorNumber)
            RsH.MoveNext
        Loop
    tnx it gave me a start

  12. #12
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] how do i color each listsubitems?

    Arno

    I don't think this will work .. BackColor does not seem to be a valid property
    Code:
    Do While Not RsH.EOF
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
        itm.SubItems(1) = ""
        itm.ListSubItems(1).BackColor = HairColor(RsH!UserColorNumber)
        RsH.MoveNext
    Loop
    I think this is the best that can be done .. ForeColor

    Code:
    Do While Not RsH.EOF
        Set itm = LsVw.ListItems.Add(, , RsH!UserName)
        itm.SubItems(1) = ""
        itm.ListSubItems(1).ForeColor = HairColor(RsH!UserColorNumber)
        RsH.MoveNext
    Loop
    EDIT

    I'm assuming that LsVw.View = lvwReport.
    FWIW, .Bold is also a usable property

    Spoo
    Last edited by Spooman; May 24th, 2017 at 01:02 PM.

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: [RESOLVED] how do i color each listsubitems?

    This is easy using a flexgrid. I steer from the listview (personal choice).

    Sam

  14. #14
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] how do i color each listsubitems?

    Sam

    I'll second that. FlexGrid is very (ahem) flexible.

    Salsa

    Despite this thread being marked Resolved, any reason not to use a FlexGrid?

    Spoo

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