In the picture 1, the radlistbox shows orange highlight color.
I am wondering how can I change the color like picture 2 as blue highlight. I tried to changed its themename, but it doesn't work.
Regards,
Fendy
13 Answers, 1 is accepted
the very best way to change the highlight colour os to define your own theme. You can find out more about using the Visual Style Builder here.
However, it is possible to change the highlight colour manually, though it's rather long winded.
First handle the PopUp Opened event on the RadDropDownList
this
.radDropDownList1.PopupOpened +=
new
EventHandler(radDropDownList1_PopupOpened);
Handle this event and loop over the visual item, adding a handler to Mouse Enter and Mouse Leave
void
radDropDownList1_PopupOpened(
object
sender, EventArgs e)
{
DefaultListControlStackContainer container = (DefaultListControlStackContainer)
this
.radDropDownList1.Popup.RootElement.Children[0].Children[1].Children[0];
foreach
(RadListVisualItem item
in
container.Children)
{
item.MouseEnter -=
new
EventHandler(Item_MouseEnter);
item.MouseEnter +=
new
EventHandler(Item_MouseEnter);
item.MouseLeave -=
new
EventHandler(item_MouseLeave);
item.MouseLeave +=
new
EventHandler(item_MouseLeave);
}
}
And change the highlight for these items
void
item_MouseLeave(
object
sender, EventArgs e)
{
((RadListVisualItem)sender).ResetValue(LightVisualElement.BackColorProperty);
((RadListVisualItem)sender).BackColor2 = Color.White;
((RadListVisualItem)sender).ResetValue(LightVisualElement.NumberOfColorsProperty);
}
void
Item_MouseEnter(
object
sender, EventArgs e)
{
((RadListVisualItem)sender).BackColor = Color.LightBlue;
((RadListVisualItem)sender).BackColor2 = Color.Blue;
((RadListVisualItem)sender).NumberOfColors = 2;
}
Hope that helps
Richard
Did this help? If so please remember to mark as answer.
If you need futher assistance, please let me know
thanks
Richard
Hi Richard,
I am not quite sure whether your codes is helpful or not, because I am using RadListControl rather than RadDropdownList, also it is created under VB.NET environment, sorry I should mentioned it at first time.
I am wondering why my RadTreeView has blue highlight when it applied VistaTheme, and this doesn’t work with my RadListControl.
Thanks,
Fendy
Unfortunately, I don't have the older version of the controls to try this out for you, but I'd advise upgrading to teh latest 2010 Q3 SP1 version as there are many enhancements, fixes and new products in the latest version which I believe would be of benefit to you.
You can also use Telerik's code converter to change code from/to C#/VB at this link but if you need further help either converting it, or with nything else, just let me know
Richard
Apologies, I re-read your post. I will prepare you a sample (if it's different) for the RadListControl. I will get back to you shortly.
Regards,
Richard
I've been trying this out, and whilst it is possible, for it to be reliable for all scenarios (different selection modes etc..) I would advise creating a new custom theme as per my above post for the RadListControl using the Visual Style Builder.
Hope that helps
Richard
Whilst I still maintain tha the best way is via VSB, I though the following might be useful for you for use with single selection RadListControl
In Form Load..
Me
.RadListControl1.SelectionMode = SelectionMode.One
Dim
container
As
DefaultListControlStackContainer =
CType
(
Me
.RadListControl1.RootElement.Children(0).Children(0), DefaultListControlStackContainer)
For
Each
item
As
RadListVisualItem
In
container.Children
AddHandler
item.MouseEnter,
AddressOf
Item_MouseEnter
AddHandler
item.MouseLeave,
AddressOf
Item_MouseLeave
AddHandler
item.MouseDown,
AddressOf
Item_MouseDown
Next
Private
Sub
Item_MouseEnter(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Dim
item
As
RadListVisualItem =
CType
(sender, RadListVisualItem)
item.BackColor = Color.LightBlue
item.BackColor2 = Color.Blue
item.NumberOfColors = 2
End
Sub
Private
Sub
Item_MouseLeave(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Dim
item
As
RadListVisualItem =
CType
(sender, RadListVisualItem)
If
Not
item.Selected
Then
item.ResetValue(LightVisualElement.BackColorProperty)
item.ResetValue(LightVisualElement.NumberOfColorsProperty)
item.BackColor2 = Color.White
End
If
End
Sub
Private
Sub
Item_MouseDown(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Dim
container
As
DefaultListControlStackContainer =
CType
(
Me
.RadListControl1.RootElement.Children(0).Children(0), DefaultListControlStackContainer)
For
Each
item
As
RadListVisualItem
In
container.Children
If
Not
item
Is
CType
(sender, RadListVisualItem)
Then
item.ResetValue(LightVisualElement.BackColorProperty)
item.ResetValue(LightVisualElement.NumberOfColorsProperty)
item.BackColor2 = Color.White
End
If
Next
End
Sub
All the best
Richard
Hi Richard,
Thank you so much for all your help I really appreciate it.
I tried to use your latest code, but it was generated an error when it fired MouseEnter Event, the error message was saying” Unable to cast object of type 'Telerik.WinControls.UI.RadListControl' to type 'Telerik.WinControls.UI.RadListVisualItem'.”
As you mentioned, solve this problem is better to use Visual Style Builder, I will try it.
Cheers,
Fendy
Out of interest what version of the controls are you using? If you are on the latest Q3 2010 SP1 version and using a radListControl then the above should work fine. If you're not, which ever method you use, I'd advise to upgrade as there are lots of enhancements, fixes and new controls in the latest version.
Let me know if you need anything further
Richard
I am using Q3 2010 Version.
I have not right to download latest version now, I will get it after some time.
Anyway, thank you very much.
Cheers,
Fendy
Thank you both for writing.
I want to share that in both Q3 2010 and Q3 2010 SP1 Richard's suggestion works fine. Note that this will work with a single selection only and glitches appear in multiple selection. Like Richard said, the best approach here is to modify the theme with Visual Stile Builder.
Additionally, I want to mention that you are able to download the latest version of our controls from your account. Simply navigate to Download Free Trials >> RadControls for WinForms >> Download Free Trial.
I hope this helps. If you have any further questions, do not hesitate to write back.
All the best,Stefan
the Telerik team
You are right, this is the wrong place to ask such a question. Please open a new thread in the appropriate section: http://www.telerik.com/community/forums/winforms/buttons.aspx. Also, in the thread, please provide information about how you change the button's color.
Thank you for the understanding.
Regards,
Stefan
the Telerik team