|
-
May 9th, 2002, 10:28 PM
#1
Thread Starter
Fanatic Member
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:
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.
-
May 9th, 2002, 10:45 PM
#2
Stuck in the 80s
When you populate your ListView, do something like this:
VB Code:
Dim ListX As ListItem
ListView1.ListItems.Add , , "Text"
ListView1.ListItems(1).ListSubItems.Add , , "Item 2"
Set ListX = ListView1.ListItems(1).ListSubItems.Add(, , "Text")
ListX.ForeColor = vbBlue
Of course, modify the code to what you need. But when you add the subitem #3, do the
VB Code:
Set ListX = ListView1.ListItems(1).ListSubItems.Add(, , "Text")
ListX.ForeColor = vbBlue
So you can set it's color as it's added to the control.
-
May 9th, 2002, 11:09 PM
#3
Thread Starter
Fanatic Member
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:
Set i = ListView1.ListItems.Add(, , File1.List(x))
i.SubItems(1) = File1.Path
i.SubItems(2) = strArtist
i.SubItems(3) = strTitle
DoEvents
-
May 10th, 2002, 09:10 AM
#4
Thread Starter
Fanatic Member
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.
-
Jun 3rd, 2002, 03:12 PM
#5
New Member
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
-
Jun 3rd, 2002, 03:28 PM
#6
Stuck in the 80s
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.
-
Jun 3rd, 2002, 03:36 PM
#7
New Member
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
-
Jun 3rd, 2002, 03:40 PM
#8
Stuck in the 80s
You can specify the color AS you add the item as I have already said twice.
VB Code:
Dim listX as ListItem
Set listX = ListView1.ListItems.Add( , , "Text")
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?
-
Jun 4th, 2002, 07:54 PM
#9
Fanatic Member
Ok, here's what you do:
Say you want to change the color of the 3rd subitem to blue.
VB Code:
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
-
Jun 4th, 2002, 10:14 PM
#10
Stuck in the 80s
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:
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.
-
Jun 8th, 2002, 02:58 PM
#11
-
Jun 8th, 2002, 04:49 PM
#12
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|