custom checkedlistbox

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 3084 Views - Last Post: 04 August 2016 - 10:16 PM Rate Topic: -----

#1 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

custom checkedlistbox

Posted 28 July 2016 - 06:40 AM

Hi,

I have created a custom checklistbox and I want to it stay permanently the same color after checking a checkbox. Also when it is drawn for the first time, a color will be added depending if the checkbox is checked

private void checklistbox_DrawItem(object sender, DrawItemEventArgs e)
{    
    // Draw the background 
    e.DrawBackground();        

    // Get the item text    
    string text = ((ComboBox)sender).Items[e.Index].ToString();

    // Determine the forecolor based on whether or not the item is selected    
    Brush brush;
    if ((e.State == CheckState.Selected) == CheckState.Selected)
    {
        [b]// To remain the same color when selected[/b]
    }
    else
    {
        // 
        // When drawing for the first time..
        // if (combobox.checked) 
        //     brush = Brushes.Red 
        // else 
        //     brush = Brushes.Green;
        //       
    }

 
    // Draw the text    
    e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}


It will still change the color if I uncheck the combobox(when first time it is checked). I want it to permanently stay as the color when shown for the first time. Is this possible?

This post has been edited by unknownmaster80: 28 July 2016 - 06:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: custom checkedlistbox

#2 aidenkael   User is offline

  • D.I.C Regular
  • member icon

Reputation: 66
  • View blog
  • Posts: 314
  • Joined: 22-October 13

Re: custom checkedlistbox

Posted 29 July 2016 - 09:44 AM

Look at your if ((e.State == CheckState.Selected) == CheckState.Selected) block. Starting with the conditional, what happens if state is false and selected is true? Or selected is true and state is false? Is this going to evaluate true or false?
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: custom checkedlistbox

Posted 29 July 2016 - 10:33 AM

I'm going to point out that a checkbox has THREE states, not two.
https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

#4 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 30 July 2016 - 05:07 PM

If it is selected, it will be true. If not it will be false.
But drawitem will also evaluate if it is checked. So if I checked it, it will still change it color. Example if the displayed color is originally Red and I want to uncheck this. It should not change to green color. I only need it to change color when displayed but not when you select uncheck.


Thanks #3 tlhIn`toq, it is DrawItemState and not checkstate.

This post has been edited by unknownmaster80: 30 July 2016 - 05:12 PM

Was This Post Helpful? 0
  • +
  • -

#5 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 31 July 2016 - 04:27 PM

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12647
  • View blog
  • Posts: 45,820
  • Joined: 27-December 08

Re: custom checkedlistbox

Posted 31 July 2016 - 04:28 PM

Please avoid needlessly bumping your thread.
Was This Post Helpful? 1
  • +
  • -

#7 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,989
  • Joined: 05-May 12

Re: custom checkedlistbox

Posted 01 August 2016 - 06:34 AM

First of all let's make sure we are talking about the same thing. This is what the default WinForms CheckedListBox looks like:
Attached Image
(courtesy of DotNetPearls.com)

In your code above, though I see a cast to ComboBox. Are we even talking about the same thing here?
Was This Post Helpful? 1
  • +
  • -

#8 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 01 August 2016 - 05:02 PM

Yes. It is the same thing. I had changed to combobox for my understanding. But I am still referring to checkedlistbox
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,989
  • Joined: 05-May 12

Re: custom checkedlistbox

Posted 01 August 2016 - 06:39 PM

No, they are no the same thing. A ComboBox is a control that has an edit control and a listbox. The edit control shows the currently selected item. A listbox is just a control that stands by itself. It does not have an associated edit control to show what is currently selected.
Was This Post Helpful? 0
  • +
  • -

#10 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 02 August 2016 - 06:59 AM

Ok..I'll take note. And I'm looking for Checkedlistbox but not listbox
Was This Post Helpful? 0
  • +
  • -

#11 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 03 August 2016 - 04:52 PM

Any ideas?
Was This Post Helpful? -1
  • +
  • -

#12 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12647
  • View blog
  • Posts: 45,820
  • Joined: 27-December 08

Re: custom checkedlistbox

Posted 03 August 2016 - 04:59 PM

I've already asked you not to bump your thread if you don't have anything to add. Remember that this is a volunteer forum and folks help as they are able/willing.
Was This Post Helpful? 0
  • +
  • -

#13 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2942
  • View blog
  • Posts: 11,425
  • Joined: 03-December 12

Re: custom checkedlistbox

Posted 03 August 2016 - 05:05 PM

Have you figured anything out on ignoring what the state is?
Was This Post Helpful? 0
  • +
  • -

#14 unknownmaster80   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 109
  • Joined: 06-August 11

Re: custom checkedlistbox

Posted 04 August 2016 - 07:45 AM

Hi Mac,

I didn't know what were you referring to the first time you said I bumped the thread..And now my reputation again..
And I was not bumping. I was just asking as there was no reply.
Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12647
  • View blog
  • Posts: 45,820
  • Joined: 27-December 08

Re: custom checkedlistbox

Posted 04 August 2016 - 07:48 AM

That is called bumping. Please do not persist in doing such.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2