{
e.VisualItem.DrawFill = false;
e.VisualItem.DrawBorder = false;
}
2 Answers, 1 is accepted
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.
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.
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.
Working perfectly, thank you so much! I have a couple of last questions:
- How can I align the header text to the left? It seems the TextAligment property is missing.
- How can I disable the header selection so that it doesn't paint in blue when selected?
Thank you in advance for your help!
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.