Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Listview BackColor problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Paris - 01 Oct 2004 17:02 GMT
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
Sijin Joseph - 01 Oct 2004 17:49 GMT
You need to set ListViewItem.UseItemStyleForSubItems = true

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I am trying to change the BackColor of an item but when I run this code, it
> doesn't change
[quoted text clipped - 7 lines]
>
> Gary
Gary Paris - 01 Oct 2004 18:26 GMT
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.

> You need to set ListViewItem.UseItemStyleForSubItems = true
>
[quoted text clipped - 13 lines]
>>
>> Gary
Gary Paris - 01 Oct 2004 18:39 GMT
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

> Can you show me where to set this?  I don't understand where to use it.  I
> tried the following
[quoted text clipped - 20 lines]
>>>
>>> Gary
Imran Koradia - 01 Oct 2004 19:55 GMT
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.

> 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"))
>                 '
> ******************************************************************
[quoted text clipped - 41 lines]
> >>>
> >>> Gary
Gary Paris - 01 Oct 2004 20:30 GMT
Thanks for your help.  It worked.

Gary

>I think he meant to set it to False. The default value is True. So instead
> of:
[quoted text clipped - 75 lines]
>> >>>
>> >>> Gary
DS - 14 Dec 2004 00:51 GMT
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

> I think he meant to set it to False. The default value is True. So instead
> of:
[quoted text clipped - 74 lines]
> > >>>
> > >>> Gary

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.