[Closed] Dotnet Listview: colored columns
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)
subItems inherit the style from the parent item (row) by default. Disable that on the row item;
lv.Items.Item[rowIndex].useItemStyleForSubItems = false
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…
Thanks guys, worked great!
(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)
[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?