Click here to Skip to main content
16,016,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Is there a way to hightlight checked items in a CheckedListview ?

What I have tried:

I have tried
C#
<pre> private void softListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            if ((e.Index >= 0) && (e.Index < softListBox.Items.Count))
            {
                bool isChecked = softListBox.GetItemChecked(e.Index);
                e.Graphics.FillRectangle(isChecked ? Brushes.LightGreen : Brushes.White, e.Bounds);
                e.Graphics.DrawString(softListBox.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds);
            }
            e.DrawFocusRectangle();
        }


But the Drawmode seems to be sticking at "Normal" using the code
C#
this.softListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
So it wont trigger, thanks ?
Posted
Comments
0x01AA 13-Aug-24 1:28am    
Looks like the only way is to derive your own CheckListBox and override protected override void OnDrawItem(DrawItemEventArgs e)
Maciej Los 20-Aug-24 14:02pm    
Sounds like an answer, Bruno.

1 solution

I don't think there is anything you can do to customise the painting of the checkedlistbox as Microsoft is already using owner draw to paint the checkboxes.

Internally it is using OwnerDrawFixed but the DrawMode property is hard coded to return DrawMode.Normal and the set part does nothing.

Alan.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900