Error: "Object of type 'Telerik.WinControls.Enumerations.ToggleState' cannot be converted to type 'System.Boolean'." To reproduce: public Form1() { InitializeComponent(); List<Parent> dataItems = new List<Parent>(); Parent currentParent; Child currentChild; List<Child> children; string parentId = string.Empty; string childId = string.Empty; for (int i = 1; i <= 5; i++) { parentId = Guid.NewGuid().ToString(); children = new List<Child>(); for (int j = 1; j < 5; j++) { childId = Guid.NewGuid().ToString(); currentChild = new Child(childId, parentId, "SubNode." + i + "." + j, j % 2 == 0); children.Add(currentChild); } currentParent = new Parent(parentId, "Node." + i, i % 2 == 0,children); dataItems.Add(currentParent); } radTreeView1.DataSource = dataItems; radTreeView1.DisplayMember = "Title\\Name"; radTreeView1.ChildMember = "Parent\\Children"; radTreeView1.CheckedMember = "IsActive\\Status"; radTreeView1.CheckBoxes = true; } public class Parent { public string ParentId { get; set; } public string Title { get; set; } public bool IsActive { get; set; } public List<Child> Children { get; set; } public Parent(string parentId, string title, bool isActive, List<Child> children) { this.ParentId = parentId; this.Title = title; this.IsActive = isActive; this.Children = children; } } public class Child { public string ChildId { get; set; } public string ParentId { get; set; } public string Name { get; set; } public bool Status { get; set; } public Child(string childId, string parentId, string name, bool status) { this.ChildId = childId; this.ParentId = parentId; this.Name = name; this.Status = status; } } Workaround: Use a custom TypeConverter for the boolean properties: public class ToggleStateConverter : TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(ToggleState); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is bool) { switch ((bool)value) { case true: return ToggleState.On; case false: return ToggleState.Off; default : return ToggleState.Indeterminate; } } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(ToggleState); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { ToggleState state = (ToggleState)value; switch (state) { case ToggleState.On: return true; case ToggleState.Off: return false; case ToggleState.Indeterminate: return false; } return base.ConvertFrom(context, culture, value); } }
To reproduce: 1. Drag and drop RadTreeView on the form. 2. Set the Dock property to true 3. Add 3 or more nodes with long names 4. Resize the form to minimum size and you will notice that the spacing between characters is changed. Workaround: If FontSize of nodes is bigger than 13, you can subscribe to the NodeFormatting event and set the AutoEllipsis property to false: Font font = new Font("Segoe UI", 13f, FontStyle.Regular); void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e) { e.NodeElement.ContentElement.Font = font; e.NodeElement.ContentElement.AutoEllipsis = false; } If font size is smaller, you need to set the MinSize property too: Font font = new Font("Segoe UI", 12f, FontStyle.Regular); void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e) { e.NodeElement.ContentElement.Font = font; e.NodeElement.ContentElement.MinSize = new System.Drawing.Size(500, 18); }
Currently we do not support binding to the ToggleState.Indeterminate state automatically because it would require a change in the behavior of the Checked property. If you use the CheckedMember, the ToggleState.Indeterminate state is represent like ToggleState.On. Workaround: Subscribe to the NodeFormatting and NodeCheckedChanged events: void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e) { Child child = e.Node.DataBoundItem as Child; if (child != null) { e.Node.CheckState = child.Status; } } void radTreeView1_NodeCheckedChanged(object sender, Telerik.WinControls.UI.TreeNodeCheckedEventArgs e) { Child child = e.Node.DataBoundItem as Child; if (child != null) { child.Status = e.Node.CheckState; } }
To reproduce: use the following code snippet and perform the illustrated steps on the attached gif file: public Form1() { InitializeComponent(); for (int i = 0; i < 5; i++) { this.radTreeView1.Nodes.Add("Node" + i); } this.radTreeView1.NodeRemoving += radTreeView1_NodeRemoving; this.radTreeView1.AllowRemove = true; this.radTreeView1.AllowDefaultContextMenu = true; } private void radTreeView1_NodeRemoving(object sender, Telerik.WinControls.UI.RadTreeViewCancelEventArgs e) { DialogResult result = RadMessageBox.Show(String.Format("Do you really want to remove the node '{0}'?", e.Node.Text), "Question", System.Windows.Forms.MessageBoxButtons.YesNo, RadMessageIcon.Question); if (result != System.Windows.Forms.DialogResult.Yes) { e.Cancel = true; } }
To reproduce: Bind the tree to the following structure: public class DeskSites { public string DeskSiteName { get; set; } public Channels channels { get; set; } } public class Channels : List<Channel> { } public class Channel { public string ChannelName { get; set; } public FileSets fileSets { get; set; } } public class FileSets : List<FileSet> { } public class FileSet { public string FileSetName { get; set; } } Workaround: Use the the generic class instead of the inherited one: public class DeskSites { public string DeskSiteName { get; set; } public List<Channel> channels { get; set; } }
To reproduce: 1. Add a RadTreeView with several nodes 2. Subscribe to the EditorRequired event and specify the editor to TreeViewTextBoxEditor where its Multiline property is set to true. 3. Select a node and press F2. The editor is activated. However, when you enter some text and press Ctrl+Enter, the editor is closed. The expected behavior is that a new line is inserted. Workaround: private void radTreeView1_EditorRequired(object sender, TreeNodeEditorRequiredEventArgs e) { CustomTreeViewTextBoxEditor editor = new CustomTreeViewTextBoxEditor(); editor.Multiline = true; e.Editor = editor; } public class CustomTreeViewTextBoxEditor : TreeViewTextBoxEditor { protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control && this.Multiline) { return; } base.OnKeyDown(e); } }
Please refer to the attached gif file. Workaround: set the Enabled property to false at run time.
Workaround: private void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e) { e.NodeElement.UseDefaultDisabledPaint = true; }
Workaround: class CustomDragDropService : TreeViewDragDropService { public CustomDragDropService(RadTreeViewElement owner) : base(owner) { } protected override void SetHintWindowPosition(Point mousePt) { } } class CustomTreeViewElement : RadTreeViewElement { protected override Type ThemeEffectiveType { get { return typeof(RadTreeViewElement); } } protected override TreeViewDragDropService CreateDragDropService() { return new CustomDragDropService(this); } } class CustomTreeView : RadTreeView { protected override RadTreeViewElement CreateTreeViewElement() { return new CustomTreeViewElement(); } public override string ThemeClassName { get { return typeof(RadTreeView).FullName; } } }
To reproduce: 1. Run Demo application >> TreeView >> Drag & Drop. 2. Change the theme to Windows7 and start dragging a node. The drop hint is missing. Workaround: apply the theme in the Form.Load event after getting the TreeViewElement.ItemDropHint property coming from the ControlDefault theme. RadImageShape hint; private void Form1_Load(object sender, EventArgs e) { hint = this.radTreeView1.TreeViewElement.ItemDropHint; this.radTreeView1.ThemeName = "Windows7"; this.radTreeView1.TreeViewElement.ItemDropHint = hint; }
Similar functionality like in KendoUI or WPF
To reproduce: add a RadTreeView and a RadButton to the form. Use the following code snippet: public Form1() { InitializeComponent(); RadTreeNode node1 = new RadTreeNode(); node1.Text = "SameText"; RadTreeNode node2 = new RadTreeNode(); node2.Text = "SameText"; this.radTreeView1.Nodes.Add(node1); this.radTreeView1.Nodes.Add(node2); this.radTreeView1.SortOrder = SortOrder.Ascending; } private void radButton1_Click(object sender, EventArgs e) { for (int i = this.radTreeView1.Nodes.Count - 1; i > -1; i--) { this.radTreeView1.Nodes.RemoveAt(i); } } Workaround: set the SortOrder property to None before removing the nodes and restore it afterwards private void radButton1_Click(object sender, EventArgs e) { this.radTreeView1.SortOrder = SortOrder.None; for (int i = this.radTreeView1.Nodes.Count - 1; i > -1; i--) { this.radTreeView1.Nodes.RemoveAt(i); } this.radTreeView1.SortOrder = SortOrder.None; }
Select Demo application >> "Tree View" -> "Drag & Drop". Focus on the left treeview. 1. Click on the node "Drafts"; 2. Press Shift button and click on the "Outbox" node; 3. Release shift button; 4. Press left mouse button on the "Outbox" node and start dragging; 5. Drop selected nodes after node "Large Mail". You can see that order of nodes was changed. Before: "Drafts", "Inbox" and "Outbox" After: "Outbox", "Drafts" and "Inbox" Possible workaround: http://www.telerik.com/forums/nodes-order-after-drag-drop#5bbz6cBDEUeHLyLU5zkfDQ
If you set the RadBreadCrumb.DefaultTreeView property to null, all items in the RadBreadCrumb should be cleared. Additionally, the subscription to the SelectedNodeChanged remains although the associated tree view is set to null. Afterwards, if you change the selected node, a NullReferenceException occurs.
To reproduce: 1. Add a RadTreeView and populate it with nodes at design time. 2. Use the following code snippet: Me.RadTreeView1.AllowDefaultContextMenu = True Me.RadTreeView1.RightToLeft = Windows.Forms.RightToLeft.Yes When you run the application and right click over a node, the context menu is not in RTL mode. Workaround: use the ContextMenuOpening event and set the TreeViewDefaultContextMenu.RightToLeft property to Yes. Private Sub RadTreeView1_ContextMenuOpening(sender As Object, e As TreeViewContextMenuOpeningEventArgs) _ Handles RadTreeView1.ContextMenuOpening Dim defaultMenu As TreeViewDefaultContextMenu = TryCast(e.Menu, TreeViewDefaultContextMenu) If defaultMenu IsNot Nothing Then defaultMenu.DropDown.RightToLeft = Windows.Forms.RightToLeft.Yes End If End Sub
To reproduces: add a RadTreeView and set up Object-relational hierarchy. Use the following code: NorthwindEntities context = new NorthwindEntities(); public Form1() { InitializeComponent(); context.Categories.Load(); context.Products.Load(); this.radTreeView1.DataSource = context.Categories.Local.ToBindingList(); this.radTreeView1.DisplayMember = "CategoryName\\ProductName"; this.radTreeView1.ChildMember = "Categories\\Products"; } private void radButton1_Click(object sender, EventArgs e) { this.radTreeView1.ChildMember = "Products\\Categories"; this.radTreeView1.DisplayMember = "ProductName\\CategoryName"; this.radTreeView1.DataSource = context.Products.Local.ToBindingList(); } When you click the RadButton, NullReferenceException occurs. Resolution: Add more descriptive exception message.
Workaround: use the NodeFormatting event to set the NodeElement.ExpanderElement.Padding to new Padding(1, 0, 0, 0)