Listview BackColor problem

G

Gary Paris

I am trying to change the BackColor of an item but when I run this code, it
doesn't change

ListView1.Items.Item(currentRow).SubItems.Item(4).BackColor =
Drawing.Color.SpringGreen



What am I doing wrong?

Thanks,

Gary
 
G

Gary Paris

Can you show me where to set this? I don't understand where to use it. I
tried the following

ListView1.Items(currentRow).UseItemStyleForSubItems = True

and it doesn't work.
 
G

Gary Paris

Here is the code I have


ListView1.Items.Add(myreader.Item("ProductID"))
ListView1.Items.Item(currentRow).SubItems.Add(myreader.Item("ProductName"))
ListView1.Items.Item(currentRow).SubItems.Add(myreader.Item("UnitsInStock"))
ListView1.Items.Item(currentRow).SubItems.Add(myreader.Item("UnitsOnOrder"))
ListView1.Items.Item(currentRow).SubItems.Add(myreader.Item("ReorderLevel"))
ListView1.Items.Item(currentRow).SubItems.Add(myreader.Item("Discontinued"))
'
******************************************************************
ListView1.Items.Item(currentRow).UseItemStyleForSubItems =
True
'
******************************************************************
If myreader.GetInt16(UNITS_INSTOCK_COLUMN) <= _
myreader.GetInt16(REORDERLEVEL_COLUMN) And _
myreader.GetInt16(UNITS_ONORDER_COLUMN) = 0 And _
myreader.GetBoolean(DISCONTINUED_COLUMN) = False Then
ListView1.Items.Item(currentRow).SubItems.Item( _
UNITS_INSTOCK_COLUMN).ForeColor = Color.White
ListView1.Items.Item(currentRow).SubItems.Item( _
UNITS_INSTOCK_COLUMN).BackColor = Color.DarkRed

If you can tell me the exact syntax that would be greatly appreciated.

Thanks,

Gary
 
I

Imran Koradia

I think he meant to set it to False. The default value is True. So instead
of:

ListView1.Items.Item(currentRow).UseItemStyleForSubItems = True

you should do:

ListView1.Items.Item(currentRow).UseItemStyleForSubItems = False

I think you need to set it before you add the subitems - after the line:
ListView1.Items.Add(myreader.Item("ProductID"))

But I'm not sure if you *absolutely* have to set it before adding the
subitems. Ofcourse, the above will definitely work.


hope that helps..
Imran.
 
G

Gary Paris

Thanks for your help. It worked.

Gary

Imran Koradia said:
I think he meant to set it to False. The default value is True. So instead
of:

ListView1.Items.Item(currentRow).UseItemStyleForSubItems = True

you should do:

ListView1.Items.Item(currentRow).UseItemStyleForSubItems = False

I think you need to set it before you add the subitems - after the line:
ListView1.Items.Add(myreader.Item("ProductID"))

But I'm not sure if you *absolutely* have to set it before adding the
subitems. Ofcourse, the above will definitely work.


hope that helps..
Imran.
 
G

Guest

guys, do you know, how to keep BackColor fro items with Selected=true ??

this colors are working fine, but when user selects item, he always see one
blue backgound color and one white text :-(

all colors are lost in selection
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top