Disable selection in RadCheckedListBox

2 Answers 56 Views
CheckedListBox
Roy
Top achievements
Rank 1
Roy asked on 24 Oct 2024, 09:18 PM | edited on 24 Oct 2024, 09:19 PM

Hi, how can I disable the selection frames in a RadCheckedListBox? I tried the following code, but it didn't work:

private void radCheckedListBox1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
        {
            e.VisualItem.DrawFill = false;
            e.VisualItem.DrawBorder = false;
        }

 

2 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 25 Oct 2024, 03:56 PM

Hello, Roy,

I have tested the code on my side and the background is removed when setting the DrawFill of the VisualItem in the VisualitemFormatting event. 
Here is the result on my side:

However, the text is almost invisible and to make it readable we need to set the ForeColor of the cells to Black in the CellFormatting event. Here is the code I am using:

private void RadCheckedListBox1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
    e.VisualItem.DrawFill = false;
    e.VisualItem.DrawBorder = false;
}

private void RadCheckedListBox1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if (e.CellElement is DetailListViewDataCellElement)
    {
        // Data cells
        e.CellElement.ForeColor = Color.Black;
    }
    else
    {
        // Header cells
        e.CellElement.ResetLocalValue(VisualElement.ForeColorProperty);
    }
}

And the visual result:

Looking at the result on your side it seems the code is not being executed. Can you check whether the VisualItemFormatting event handler is attached to the event of the CheckedListBox?

Let me know the results. 

Regards,
Todor
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roy
Top achievements
Rank 1
commented on 25 Oct 2024, 09:11 PM

Hi Todor, thanks for the reply! It seems I wasn’t clear,   I’m trying to remove the black frame. When I click on a row, I don’t want a black frame to appear around the cell.

0
Nadya | Tech Support Engineer
Telerik team
answered on 30 Oct 2024, 11:45 AM

Hello, Roy,

To remove the cell border you should set DrawBorder to false in CellFormatting event:

private void RadCheckedListBox1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if (e.CellElement is DetailListViewDataCellElement)
    {
        // Data cells
        e.CellElement.DrawBorder = false;
    }
}

I hope this helps. If you have any other questions do not hesitate to contact us.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roy
Top achievements
Rank 1
commented on 03 Nov 2024, 10:38 AM | edited

Working perfectly, thank you so much! I have a couple of last questions:

  1. How can I align the header text to the left? It seems the TextAligment property is missing.
  2. How can I disable the header selection so that it doesn't paint in blue when selected?

Thank you in advance for your help!

Nadya | Tech Support Engineer
Telerik team
commented on 06 Nov 2024, 08:54 AM

Hello, Roy,

1. To align the header text you should access the DetailListViewHeaderCellElement which represents the header cells in RadCheckedListBox control. Then, use the TextAlignment property, it is not missing. You can do this in the CellFormatting event.

2. To achieve this, you should again use the same event and override the theme settings at run time by specifying the desired property and color which you need to change. Here is suitable to use the SetThemeValueOverride(). Note, when you change the back color and remove the blue color you should also update the text color since it changes to white when the blue color is applied. To use the default coloring you can use the back color transparent of the cell and black text color to make the header text visible.

I prepared a code snippet that covers both of your questions:

private void RadCheckedListBox1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if (e.CellElement is DetailListViewHeaderCellElement)
    {
        e.CellElement.TextAlignment = ContentAlignment.MiddleLeft;
        e.CellElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty, Color.Transparent, "DetailListViewHeaderCellElement.ContainsMouse.MouseOver");
        e.CellElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.ForeColorProperty, Color.Black, "DetailListViewHeaderCellElement.ContainsMouse.MouseOver");
    }
}

I hope this helps. Please let me know if I can assist you further. 

Tags
CheckedListBox
Asked by
Roy
Top achievements
Rank 1
Answers by
Todor
Telerik team
Nadya | Tech Support Engineer
Telerik team
Share this question
or