Results 1 to 12 of 12

Thread: Listview text color issue

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Listview text color issue

    Ok this is an odd one. In my program, after I populate listitems into my listview, I want to set the Subitems(3) forecolor to blue.

    So my subitems column text will be a different color than the main listitems column. The following code works, but it only changes the forecolor of the first listitems subitem(3). It should change the entire column not just one why is it doing this?
    VB Code:
    1. ListView1.ListItems(1).ListSubItems(3).ForeColor = vbBlue
    Where should I have this line of code? Right after I populate the listview? Any explanation is appreciated. Thanks.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    When you populate your ListView, do something like this:

    VB Code:
    1. Dim ListX As ListItem
    2.  
    3.   ListView1.ListItems.Add , , "Text"
    4.   ListView1.ListItems(1).ListSubItems.Add , , "Item 2"
    5.   Set ListX = ListView1.ListItems(1).ListSubItems.Add(, , "Text")
    6.   ListX.ForeColor = vbBlue

    Of course, modify the code to what you need. But when you add the subitem #3, do the

    VB Code:
    1. Set ListX = ListView1.ListItems(1).ListSubItems.Add(, , "Text")
    2.   ListX.ForeColor = vbBlue

    So you can set it's color as it's added to the control.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Ok I'm confused.......

    I've really confused myself now! How can I do the above with the below code. I want subitems(3) color to change.
    VB Code:
    1. Set i = ListView1.ListItems.Add(, , File1.List(x))
    2.         i.SubItems(1) = File1.Path
    3.         i.SubItems(2) = strArtist
    4.         i.SubItems(3) = strTitle
    5.        
    6.        
    7.     DoEvents

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Anyone?

    I'm not wanting to change around my entire code that adds the listitems. Is there a way I can integrate the textcolor of the subitems into my code. Any help is appreciated.

  5. #5
    New Member
    Join Date
    Feb 2002
    Posts
    12

    Thumbs up

    To color all of the column, you have to place your code in a loop.

    if you want subitem(3) to be red, then

    for i = 1 to listview1.listitems.count
    listview1.listitems(i).listsubitems(3).forecolor=vbred
    next


    Works on my station

    Ken Mason
    ken mason

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Anyone?

    Originally posted by hipopony66
    I'm not wanting to change around my entire code that adds the listitems. Is there a way I can integrate the textcolor of the subitems into my code. Any help is appreciated.
    Have you read my above post? A loop would be pointless when you can specify the color as the item is added, as I have shown.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    New Member
    Join Date
    Feb 2002
    Posts
    12
    Ok. My brain is dead today. I can only see two ways to do this. Either change the color as you enter the data, in which case you would have to add a line under the listview1.listitem.add

    or

    After you populate the data, call the procedure I wrote to quickly change the color.

    I have looked to see if you can preset the color of the columns and have found nothing to do so. It is completely controlled by the OCX, therefore was probably not built in. Like many other OCX's, I think this one has to be coded.

    But then again, I've been wrong before and will be wrong again. I just haven't found any other work around for this issue.

    Ken Mason
    Ottawa, Canada
    ken mason

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You can specify the color AS you add the item as I have already said twice.

    VB Code:
    1. Dim listX as ListItem
    2.  
    3. Set listX = ListView1.ListItems.Add( , , "Text")
    4. listX.ForeColor = vbBlue

    Yes, I know this colors the first column, but it is only an example. So again I say, if you can do this as the item is added, why waste time with the loop?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Ok, here's what you do:
    Say you want to change the color of the 3rd subitem to blue.
    VB Code:
    1. ListView1.ListItems(X).ListSubItems(3).ForeColor = RGB(0,0,255)
    That's all there is to it. You don't have to set a new object to it at all.

    -Excalibur
    Last edited by ExcalibursZone; Jun 4th, 2002 at 08:44 PM.
    -Excalibur

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ExcalibursZone
    Ok, here's what you do:
    Say you want to change the color of the 3rd subitem to blue.
    VB Code:
    1. ListView1.ListItems(X).ListSubItems(3).ForeColor = RGB(0,0,255)
    That's all there is to it. You don't have to set a new object to it at all.

    -Excalibur
    You can't do ListView1.ListItems(X). You'd have to know the index number. How are you going to find out the index number of the ListItem that was just added? Of course you can do "ListView1.ListItems(ListView1.ListItems.Count).ListSubItems(3).ForeColor = RGB(0, 0, 255)" The object was just an easier way to do it.

    But I'm sorry, throwing in (X) in the index spot isn't going to do it. I know you probably know that, and you just put it there to indicate that's where the Index went, but the person that asked the question probably doesn't. That's why you need to be specific.

    This thread and it's answer has been reiterated way to many times. If the questioner doesn't understand by now, there's no hope for them.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    *nodnod* I just put it there to mean any listitem with listsubitem(3) in it. it could be listview1.selecteditem.listsubitems(3), listview1.listitems(listview1.listitems.count).listsubitems(3), or in a for loop, using x to change all the listsubitems(3) in the listview to blue.

    Whether or not someone seems to get it or not, I still try to help and if the person asks again, I'll point them to this post and try to explain it in a more simple fashion if that's what it takes I'm here to help and to recieve help when I need it that is exactly what this forum is for

    -Excalibur
    -Excalibur

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ExcalibursZone
    *nodnod* I just put it there to mean any listitem with listsubitem(3) in it. it could be listview1.selecteditem.listsubitems(3), listview1.listitems(listview1.listitems.count).listsubitems(3), or in a for loop, using x to change all the listsubitems(3) in the listview to blue.

    Whether or not someone seems to get it or not, I still try to help and if the person asks again, I'll point them to this post and try to explain it in a more simple fashion if that's what it takes I'm here to help and to recieve help when I need it that is exactly what this forum is for

    -Excalibur
    Thanks for the lecture. I don't recall asking about the moral issues and true purposes of the forum. This thread was awhile ago and I don't quite remember it. I offered my solution. You offered yours. I don't think the author of the question is even checking this anymore, so it doesn't matter.

    G'day.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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