PDA

View Full Version : Dotnet Listview: colored columns


diffx
12-18-2008, 06:48 PM
I've got a listview with 2 columns and several items in it. These items (rows) all have different colors, but I can't figure out how to color every single SubItem.

This part:

TheListView.Items.Item[0].backcolor = ((DotNetClass "System.Drawing.Color").fromargb 0 0 0 )

Works fine.

TheListView.Items.Item[0].Subitems.Item[0].backcolor = ((DotNetClass "System.Drawing.Color").fromargb 0 0 0 )

Also works fine. Well, that's what I thought. Because:

TheListView.Items.Item[0].Subitems.Item[1].backcolor = ((DotNetClass "System.Drawing.Color").fromargb 0 0 0 )

Doesn't do anything.

So basically: Item[0] works, Item[0].Subitems.Item[0] works, but Item[0].Subitems.Item[1] doesn't. There is data in both 0 and 1, and both of them can be printed fine with Subitems.Item[x].text.

Showproperties does give a "backcolor" for Subitem.Item[x] but that may be inherited from it's parent. So why does Subitem.Item[1] not inherit it from the parent? Is it not possible to color Subitems?

If anyone can shine a light on this, thanks.

(tested on XP64, Max 2008 x64 and Vista32, Max 2008 x32)

ZeBoxx2
12-18-2008, 08:13 PM
subItems inherit the style from the parent item (row) by default. Disable that on the row item;

lv.Items.Item[rowIndex].useItemStyleForSubItems = false

Zbuffer
12-18-2008, 08:17 PM
Hi,

I remember having a hard time with this...
You need to set the .UseItemStyleForSubItems properties to false when you add items.

li=TheListView.Items.Add "test"
li.UseItemStyleForSubItems=false

hmmm not fast enough...

diffx
12-19-2008, 09:31 AM
Thanks guys, worked great!

(Still, why does subitem[0] have influence on the item color, while subitem[1] doesn't?)

ZeBoxx2
12-19-2008, 11:40 AM
(Still, why does subitem[0] have influence on the item color, while subitem[1] doesn't?)
Because the style for subItem[0] is the same (internally) as for its parent Item;


-- get initial colors
col = lv.items.item[0].subItems.Item[0].backColor
dotNetObject:System.Drawing.Color
(color col.r col.g col.b)
(color 255 255 255)

col = lv.items.item[0].backColor
dotNetObject:System.Drawing.Color
(color col.r col.g col.b)
(color 255 255 255)

-- change color of the subItem
col = lv.items.item[0].subItems.Item[0].backColor = (dotNetClass "System.Drawing.Color").Red
dotNetObject:System.Drawing.Color
(color col.r col.g col.b)
(color 255 0 0)

-- check the parent Item
col = lv.items.item[0].backColor
dotNetObject:System.Drawing.Color
(color col.r col.g col.b)
(color 255 0 0)

diffx
12-19-2008, 03:40 PM
Thanks Richard. I'll publish the script I've used this for soon :)

diffx
06-11-2009, 02:53 PM
[Bump old thread]

I've got a new problem which seems to be similar to the problem above: I can't set the text color of a System.Windows.Forms.Button. Changing it's forecolor affects the border, not the text color.

Changing the forecolor of it's parent, a listview, does change the text color. However, I want to change this independently for every button.

I assume I need something like useItemStyleForSubItems, but instead of SubItems, aimed at controls.

Can anyone shine a light on this?

CGTalk Moderation
06-11-2009, 02:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.