13 Answers, 1 is accepted
Thank you for writing.
To change this behavior, you will have to create your own checkbox element, inheriting from RadCheckBoxElement and change the logic in the KeyDown event. You will also have to create your check box control, inheriting from RadCheckBox and override the CreateButtonElement to return your checkbox element. Here is a code snippet which demonstrates this:
public class MyCheckBoxElement : RadCheckBoxElement{ protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { return; } base.OnKeyDown(e); } protected override Type ThemeEffectiveType { get { return typeof(RadCheckBoxElement); } }}public class MyCheckBox : RadCheckBox{ protected override RadButtonElement CreateButtonElement() { return new MyCheckBoxElement(); } public override string ThemeClassName { get { return typeof(RadCheckBox).FullName; } }}I hope you will be this useful. If you have further questions, I would be glad to help.
Regards,
Ivan Petrov
the Telerik team
I have created my custom CheckBox but can I ask you how to use this checkbox in a RadTreeNode?
I couldn't do this by checkType!
Your guide is appreciated in advance.
Ragards
Thank you for writing.
In order to use your custom check box in a tree node you will have to create a custom tree node element and replace the default ones. To replace the check box inside a TreeNodeElement you can override the CreateToggleElement method. To make RadTreeView to use your node elements you can subscribe for the CreateNodeElement event. Here is an example:
A custom check box:
public class MyCheckBoxElement : TreeNodeCheckBoxElement{ protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { return; } base.OnKeyDown(e); } protected override Type ThemeEffectiveType { get { return typeof(RadCheckBoxElement); } }}A custom tree node element:
public class MyTreeNodeElement : TreeNodeElement{ protected override RadToggleButtonElement CreateToggleElement() { if (this.Data.CheckType == CheckType.CheckBox) { return new MyCheckBoxElement(); } return base.CreateToggleElement(); } protected override Type ThemeEffectiveType { get { return typeof(TreeNodeElement); } }}And replacing the tree elements:
this.radTreeView1.CreateNodeElement += radTreeView1_CreateNodeElement;private void radTreeView1_CreateNodeElement(object sender, CreateTreeNodeElementEventArgs e){ e.NodeElement = new MyTreeNodeElement();}I hope this will help. Feel free to write back with any further questions.
Greetings,
Ivan Petrov
the Telerik team
Your kindly help is more appreciated if you provide me a sample for this solution.
Regards.
I have tested this with the latest version and it is working fine on my side. Could you please check the attached video and let me know what else I need to do in order to reproduce this?
I am looking forward to your reply.
Dimitar
Telerik by Progress
This is my derived checkbox : it does not fire togglestatechanged event with my version of telerik
using System;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace Iap.WinApp.Controls.CheckBox
{
public class QCheckBoxTest : RadCheckBox
{
public override string ThemeClassName
{
get { return typeof (RadCheckBox).FullName; }
}
protected override RadButtonElement CreateButtonElement()
{
return new MyCheckBoxElementTest();
}
}
public class MyCheckBoxElementTest : RadCheckBoxElement
{
protected override Type ThemeEffectiveType
{
get { return typeof (RadCheckBoxElement); }
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
return;
}
base.OnKeyDown(e);
}
}
}
Which version of the suite are you currently using? And how you are changing the toggle state, with the mouse or the keyboard?
I am looking forward to your reply.
Dimitar
Telerik by Progress
version 2015.3.930.40
toggle with mouse
I was able to reproduce this with the version that you are using. Here is how you can trigger the event:
public class QCheckBoxTest : RadCheckBox{ public override string ThemeClassName { get { return typeof(RadCheckBox).FullName; } } protected override RadButtonElement CreateButtonElement() { var el = new MyCheckBoxElementTest(); el.ToggleStateChanged += El_ToggleStateChanged; return el; } private void El_ToggleStateChanged(object sender, StateChangedEventArgs args) { this.OnToggleStateChanged(args); }}Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Telerik by Progress
thanks
does the problem not occur in the latest telerik version ?
This working fine with the latest version.
Regards,
Dimitar
Telerik by Progress
