Results 1 to 7 of 7

Thread: How to change color of an individual item in checkedlistbox

  1. #1
    paldebu78 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    5
    Reputation
    0

    Unhappy How to change color of an individual item in checkedlistbox

    I am working on visual studio 2005. I have put a checkedlistbox on a windows form (in vb.net) and adding items in the checkedlistbox from database. Is there any way I can set the color of some of the items in the checkedlistbox red and others black based on some condition? If there is any way how can I do that? Please help

  2. #2
    vinnie881 is offline VB.NET Forum Genius
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Sep 2006
    Posts
    152
    Reputation
    98
    I would strongly suggest using a datagrid rather then a checked list box. It will save you many future head aches. The way to change the background color conditionally is to create a new control and inherit the datagridboolcolumn. and override the "Paint". In the code for your override paint sub Do all your conditional formating then just call mybase.paint, and substitute the background, or foreground color that you chose based on your conditional formating. If you have any issues let me know, and I can give you some working code on this. Check out syncfusion conditional format datagrid, and you should be led to a article that explains this step by step.

  3. #3
    paldebu78 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    5
    Reputation
    0

    Unhappy Re:

    But I have to implement it in checkedlistbox. Is there no way I can implement it without making an ocx?

  4. #4
    vinnie881 is offline VB.NET Forum Genius
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Sep 2006
    Posts
    152
    Reputation
    98
    I believe you can do it the same way as described above, just override the CheckedListItem paint even.

  5. #5
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,508
    Reputation
    1609
    Please post in the most appropriate forum for the topic. The VS.NET General forum is for general questions regarding the IDE. This is not an IDE-related question.

    Moved.

  6. #6
    morbidreich is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2008
    Posts
    1
    Reputation
    0
    Quote Originally Posted by vinnie881 View Post
    I believe you can do it the same way as described above, just override the CheckedListItem paint even.
    Could you please explain with more details? Maybe some coding example?
    Thanks in advantage for any help.

  7. #7
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,451
    Reputation
    2727
    CheckedListBox does not support OwnerDraw mode, ListView control can do that (Listview.DrawItem documentation has code sample). Also DataGridView control can be used easier.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking