This is a migrated thread and some comments may be shown as answers.

Inability to set the ComboBox.SelectedValue when ToolWindow.DockState = AutoHide

18 Answers 244 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Dan Foster
Top achievements
Rank 2
Dan Foster asked on 19 Jan 2011, 05:01 PM
Hi,

I'm using VS2010 with Q3 (2010.3.10.1215) in Win7.

I'm having issues with being able to set the SelectedValue of a ComboBox (standard windows forms control) that was created and added to a ToolWindow while the ToolWindow.DockState = AutoHide. When the DockState is Dockable, the value can be set without issues.

I have 2 ToolWindows: ToolWindow1 contains a RadTreeView and ToolWindow2 contains various controls (ComboBoxes, TextBoxes, etc). Depending on the node the user selects certain controls are created, added to the ToolWindow and then the values set. This works fine if ToolWindow2 isn't in AutoHide when the user selects a different node. If the user AutoHides ToolWindow2 and then changes nodes, the SelectedValue for the combobox remains null. However, the text value of the textboxes can be set regardless of the DockState.

Note: If I use the SelectedIndex instead of SelectedValue I get an ArgumentOutOfRangeException when the ToolWindow.DockState = AutoHide even though the DataSource of the ComboBox is not null and has more than enough rows for the chosen Index. 

I am currently using a work around by using the the AutoHideWindowDisplayed event which calls the RadTreeView_SelectedNodeChanged event. Unfortunately, this isn't ideal because the ToolWindow2 starts off empty for a split second then suddenly the controls appear. I have tried the AutoHideWindowDisplaying event, however this did not change the stated behaviour; the SelectedValue of the ComboBoxes remained null;

Any ideas?

Kind Regards

18 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 19 Jan 2011, 06:12 PM
Hi Dan,

I've tried a very simple exmaple of this, and haven't been able to replicate your issue (this may be because I haven't yet implemented everything that you are doing. Please can you try the below in a new project and let me know if it works for you.

If you AutoHide ToolWindow1, and then check one of the nodes in the treeview, then the correseponding drop down item should be selected. I have also attached a video which can be found here

Designer File (VB)
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
  
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
  
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
  
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim RadTreeNode1 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadTreeNode2 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadTreeNode3 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadTreeNode4 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadTreeNode5 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadTreeNode6 As Telerik.WinControls.UI.RadTreeNode = New Telerik.WinControls.UI.RadTreeNode()
        Dim RadListDataItem1 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
        Dim RadListDataItem2 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
        Dim RadListDataItem3 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
        Dim RadListDataItem4 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
        Dim RadListDataItem5 As Telerik.WinControls.UI.RadListDataItem = New Telerik.WinControls.UI.RadListDataItem()
        Me.RadDock1 = New Telerik.WinControls.UI.Docking.RadDock()
        Me.DocumentContainer1 = New Telerik.WinControls.UI.Docking.DocumentContainer()
        Me.ToolWindow1 = New Telerik.WinControls.UI.Docking.ToolWindow()
        Me.RadTreeView1 = New Telerik.WinControls.UI.RadTreeView()
        Me.ToolTabStrip1 = New Telerik.WinControls.UI.Docking.ToolTabStrip()
        Me.ToolWindow2 = New Telerik.WinControls.UI.Docking.ToolWindow()
        Me.ToolTabStrip2 = New Telerik.WinControls.UI.Docking.ToolTabStrip()
        Me.RadDropDownList1 = New Telerik.WinControls.UI.RadDropDownList()
        CType(Me.RadDock1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.RadDock1.SuspendLayout()
        CType(Me.DocumentContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadTreeView1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.ToolWindow1.SuspendLayout()
        CType(Me.ToolTabStrip1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.ToolTabStrip1.SuspendLayout()
        Me.ToolWindow2.SuspendLayout()
        CType(Me.ToolTabStrip2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.ToolTabStrip2.SuspendLayout()
        CType(Me.RadDropDownList1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadDock1
        '
        Me.RadDock1.ActiveWindow = Me.ToolWindow1
        Me.RadDock1.Controls.Add(Me.ToolTabStrip2)
        Me.RadDock1.Controls.Add(Me.ToolTabStrip1)
        Me.RadDock1.Controls.Add(Me.DocumentContainer1)
        Me.RadDock1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadDock1.DocumentManager.DocumentInsertOrder = Telerik.WinControls.UI.Docking.DockWindowInsertOrder.InFront
        Me.RadDock1.IsCleanUpTarget = True
        Me.RadDock1.Location = New System.Drawing.Point(0, 0)
        Me.RadDock1.MainDocumentContainer = Me.DocumentContainer1
        Me.RadDock1.Name = "RadDock1"
        Me.RadDock1.Padding = New System.Windows.Forms.Padding(5)
        '
        '
        '
        Me.RadDock1.RootElement.MinSize = New System.Drawing.Size(25, 25)
        Me.RadDock1.Size = New System.Drawing.Size(646, 494)
        Me.RadDock1.SplitterWidth = 4
        Me.RadDock1.TabIndex = 0
        Me.RadDock1.TabStop = False
        Me.RadDock1.Text = "RadDock1"
        '
        'DocumentContainer1
        '
        Me.DocumentContainer1.Location = New System.Drawing.Point(413, 5)
        Me.DocumentContainer1.Name = "DocumentContainer1"
        '
        '
        '
        Me.DocumentContainer1.RootElement.MinSize = New System.Drawing.Size(25, 25)
        Me.DocumentContainer1.Size = New System.Drawing.Size(228, 484)
        Me.DocumentContainer1.SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Fill
        Me.DocumentContainer1.SplitterWidth = 4
        Me.DocumentContainer1.TabIndex = 0
        Me.DocumentContainer1.TabStop = False
        '
        'ToolWindow1
        '
        '
        'RadTreeView1
        '
        Me.RadTreeView1.BackColor = System.Drawing.SystemColors.Window
        Me.RadTreeView1.CheckBoxes = True
        Me.RadTreeView1.Cursor = System.Windows.Forms.Cursors.Default
        Me.RadTreeView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadTreeView1.Font = New System.Drawing.Font("Segoe UI", 8.25!)
        Me.RadTreeView1.ForeColor = System.Drawing.Color.Black
        Me.RadTreeView1.Location = New System.Drawing.Point(0, 0)
        Me.RadTreeView1.Name = "RadTreeView1"
        RadTreeNode1.ShowCheckBox = True
        RadTreeNode1.Text = "Node1"
        RadTreeNode2.ShowCheckBox = True
        RadTreeNode2.Text = "Node2"
        RadTreeNode3.ShowCheckBox = True
        RadTreeNode3.Text = "Node3"
        RadTreeNode4.ShowCheckBox = True
        RadTreeNode4.Text = "Node4"
        RadTreeNode5.ShowCheckBox = True
        RadTreeNode5.Text = "Node5"
        RadTreeNode6.ShowCheckBox = True
        RadTreeNode6.Text = "Node6"
        Me.RadTreeView1.Nodes.Add(RadTreeNode1)
        Me.RadTreeView1.Nodes.Add(RadTreeNode2)
        Me.RadTreeView1.Nodes.Add(RadTreeNode3)
        Me.RadTreeView1.Nodes.Add(RadTreeNode4)
        Me.RadTreeView1.Nodes.Add(RadTreeNode5)
        Me.RadTreeView1.Nodes.Add(RadTreeNode6)
        Me.RadTreeView1.RightToLeft = System.Windows.Forms.RightToLeft.No
        '
        '
        '
        Me.RadTreeView1.RootElement.ForeColor = System.Drawing.Color.Black
        Me.RadTreeView1.Size = New System.Drawing.Size(198, 458)
        Me.RadTreeView1.TabIndex = 0
        Me.RadTreeView1.Text = "RadTreeView1"
        Me.ToolWindow1.Controls.Add(Me.RadTreeView1)
        Me.ToolWindow1.Location = New System.Drawing.Point(1, 24)
        Me.ToolWindow1.Name = "ToolWindow1"
        Me.ToolWindow1.Size = New System.Drawing.Size(198, 458)
        Me.ToolWindow1.Text = "ToolWindow1"
        '
        'ToolTabStrip1
        '
        Me.ToolTabStrip1.Controls.Add(Me.ToolWindow1)
        Me.ToolTabStrip1.Location = New System.Drawing.Point(209, 5)
        Me.ToolTabStrip1.Name = "ToolTabStrip1"
        '
        '
        '
        Me.ToolTabStrip1.RootElement.MinSize = New System.Drawing.Size(25, 25)
        Me.ToolTabStrip1.SelectedIndex = 0
        Me.ToolTabStrip1.Size = New System.Drawing.Size(200, 484)
        Me.ToolTabStrip1.TabIndex = 1
        Me.ToolTabStrip1.TabStop = False
        '
        'ToolWindow2
        '
        Me.ToolWindow2.Controls.Add(Me.RadDropDownList1)
        Me.ToolWindow2.Location = New System.Drawing.Point(1, 24)
        Me.ToolWindow2.Name = "ToolWindow2"
        Me.ToolWindow2.Size = New System.Drawing.Size(198, 458)
        Me.ToolWindow2.Text = "ToolWindow2"
        '
        'ToolTabStrip2
        '
        Me.ToolTabStrip2.Controls.Add(Me.ToolWindow2)
        Me.ToolTabStrip2.Location = New System.Drawing.Point(5, 5)
        Me.ToolTabStrip2.Name = "ToolTabStrip2"
        '
        '
        '
        Me.ToolTabStrip2.RootElement.MinSize = New System.Drawing.Size(25, 25)
        Me.ToolTabStrip2.SelectedIndex = 0
        Me.ToolTabStrip2.Size = New System.Drawing.Size(200, 484)
        Me.ToolTabStrip2.TabIndex = 2
        Me.ToolTabStrip2.TabStop = False
        '
        'RadDropDownList1
        '
        RadListDataItem1.Text = "Node 1"
        RadListDataItem1.TextWrap = True
        RadListDataItem2.Text = "Node 2"
        RadListDataItem2.TextWrap = True
        RadListDataItem3.Text = "Node 3"
        RadListDataItem3.TextWrap = True
        RadListDataItem4.Text = "Node 4"
        RadListDataItem4.TextWrap = True
        RadListDataItem5.Text = "Node 5"
        RadListDataItem5.TextWrap = True
        Me.RadDropDownList1.Items.Add(RadListDataItem1)
        Me.RadDropDownList1.Items.Add(RadListDataItem2)
        Me.RadDropDownList1.Items.Add(RadListDataItem3)
        Me.RadDropDownList1.Items.Add(RadListDataItem4)
        Me.RadDropDownList1.Items.Add(RadListDataItem5)
        Me.RadDropDownList1.Location = New System.Drawing.Point(19, 59)
        Me.RadDropDownList1.Name = "RadDropDownList1"
        Me.RadDropDownList1.ShowImageInEditorArea = True
        Me.RadDropDownList1.Size = New System.Drawing.Size(162, 21)
        Me.RadDropDownList1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(646, 494)
        Me.Controls.Add(Me.RadDock1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.RadDock1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.RadDock1.ResumeLayout(False)
        CType(Me.DocumentContainer1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadTreeView1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ToolWindow1.ResumeLayout(False)
        CType(Me.ToolTabStrip1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ToolTabStrip1.ResumeLayout(False)
        Me.ToolWindow2.ResumeLayout(False)
        Me.ToolWindow2.PerformLayout()
        CType(Me.ToolTabStrip2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ToolTabStrip2.ResumeLayout(False)
        CType(Me.RadDropDownList1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
  
    End Sub
    Friend WithEvents RadDock1 As Telerik.WinControls.UI.Docking.RadDock
    Friend WithEvents ToolWindow1 As Telerik.WinControls.UI.Docking.ToolWindow
    Friend WithEvents RadTreeView1 As Telerik.WinControls.UI.RadTreeView
    Friend WithEvents ToolTabStrip2 As Telerik.WinControls.UI.Docking.ToolTabStrip
    Friend WithEvents ToolWindow2 As Telerik.WinControls.UI.Docking.ToolWindow
    Friend WithEvents RadDropDownList1 As Telerik.WinControls.UI.RadDropDownList
    Friend WithEvents ToolTabStrip1 As Telerik.WinControls.UI.Docking.ToolTabStrip
    Friend WithEvents DocumentContainer1 As Telerik.WinControls.UI.Docking.DocumentContainer
  
End Class

Form1.vb
Imports Telerik.WinControls.UI.Docking
Imports Telerik.WinControls.RadControlSpy
Imports Telerik.WinControls.UI
Imports Telerik.WinControls.Primitives
Imports Telerik.WinControls.Layouts
Imports Telerik.WinControls
  
Public Class Form1
  
    Private Sub RadTreeView1_NodeCheckedChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.RadTreeViewEventArgs) Handles RadTreeView1.NodeCheckedChanged
        If e.Node.Checked Then
            Me.RadDropDownList1.SelectedIndex = e.Node.Index
        End If
    End Sub
End Class

Regards,
Richard

P.S - i am also using 2010 Q3 SP1 and am running Windows7 64bit under VS2010
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 10:04 AM
Hi Richard

Thanks for your reply. It doesn't seem to be an issue if the controls were created/drawn at design time. The issue is more when they are created/drawn dynamically at run time and while the ToolWindow.DockState = AutoHide. If the ToolWindow.DockState = Dockable when the controls are added to it, it's fine. 

At design time I added a RadDock and created 2 ToolWindows. In ToolWindow1 add a RadTreeView (Dock=Fill) and in ToolWindow2 add a standard windows forms Panel control (Dock = Fill). All properties are at their default except the Tree & Panel which are docked to fill.

Form1.Designer (C#): 
private Telerik.WinControls.UI.Docking.RadDock radDock1;
private Telerik.WinControls.UI.Docking.ToolWindow toolWindow1;
private Telerik.WinControls.UI.RadTreeView radTreeView1;
private Telerik.WinControls.UI.Docking.ToolTabStrip toolTabStrip2;
private Telerik.WinControls.UI.Docking.ToolWindow toolWindow2;
private System.Windows.Forms.Panel panel1;
private Telerik.WinControls.UI.Docking.ToolTabStrip toolTabStrip1;
private Telerik.WinControls.UI.Docking.DocumentContainer documentContainer1;

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace Sample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radTreeView1.Nodes.Add("Node 1");
            radTreeView1.Nodes.Add("Node 2");
            radTreeView1.Nodes.Add("Node 3");
        }
        private ComboBox CreateCombo()
        {
            ComboBox _cmb = new ComboBox();
            _cmb.Visible = true;
            _cmb.DataSource = CreateDataSource();
            _cmb.DisplayMember = "Display";
            _cmb.ValueMember = "Value";
            return _cmb;
        }
 
        private DataTable CreateDataSource()
        {
            //create datatable for combo datasource
            DataTable _dt = new DataTable("Data");
            _dt.Columns.Add("Value", Type.GetType("System.Int32"));
            _dt.Columns.Add("Display", Type.GetType("System.String"));
            DataRow _row = _dt.NewRow();
            _row[0] = (int)0;
            _row[1] = " -- Select --";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)1;
            _row[1] = "ComboBox Value: Something 1";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)2;
            _row[1] = "ComboBox Value: Something 2";
            _dt.Rows.Add(_row);
            return _dt;
        }
 
        private void DisposeControls()
        {
            int _cnt = panel1.Controls.Count;
            for (int i = _cnt - 1; i > -1; i--)
            {
                Control _cntrl = panel1.Controls[i];
                panel1.Controls.Remove(_cntrl);
                _cntrl.Dispose();
 
            }
           
        }
 
        private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
        {
            DisposeControls();
            ComboBox _cmb1 = CreateCombo();
            _cmb1.Dock = DockStyle.Top;
            TextBox _txt1 = new TextBox();
            _txt1.Dock = DockStyle.Top;
 
            switch (radTreeView1.SelectedNode.Text)
            {
 
                case "Node 1":
                    panel1.Controls.Add(_cmb1);
                    _cmb1.SelectedValue = 1;
                     break;
                case "Node 2":
                    panel1.Controls.Add(_txt1);
                    _txt1.Text = "Nod2: Hello World";
                    break;
                case "Node 3":
                    panel1.Controls.Add(_cmb1);
                    panel1.Controls.Add(_txt1);
                    _txt1.Text = "Node 3: Hello Again";
                    _cmb1.SelectedValue = 2;
 
                    break;
            }
        }
 
 
    }
}

The controls are created and added to the tool window dynamically at runtime which is dependant on the current node. Set the ToolWindow2.DockState to AutoHide then change nodes. You'll see that the ComboBox.SelectedValue remains null. If you use SelectedIndex, you'll end up with an exception error. This only happens with ComboBoxes and only happens if the ToolWindow.DockState = AutoHide when the controls are created and added to it.

If the ToolWindow is in some sort of visible state (eg Dockable) when the controls are created and added, then placed in AutoHide mode and then back to a Dockable state (without changing nodes) it all works fine.

Something appears to be happening within the Telerik control when it's in AutoHide that prevents the value of the ComboBox value or index to be set. This also happens if you try to set the value of a ComboBox prior to adding the control to the form. 
eg:
private void Form1_Load(object sender, EventArgs e)
        {
     ComboBox _cmb1 = CreateCombo();
            _cmb1.SelectedValue = 1; //if you set the value here before adding it to the form the value remains null
            this.Controls.Add(_cmb1);
//if you set the value here after adding it to the form, it works.
        }
 
 private ComboBox CreateCombo()
        {
            ComboBox _cmb = new ComboBox();
            _cmb.Visible = true;
            _cmb.DataSource = CreateDataSource();
            _cmb.DisplayMember = "Display";
            _cmb.ValueMember = "Value";
            return _cmb;
        }
 
        private DataTable CreateDataSource()
        {
            //create datatable for combo datasource
            DataTable _dt = new DataTable("Data");
            _dt.Columns.Add("Value", Type.GetType("System.Int32"));
            _dt.Columns.Add("Display", Type.GetType("System.String"));
            DataRow _row = _dt.NewRow();
            _row[0] = (int)0;
            _row[1] = " -- Select --";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)1;
            _row[1] = "ComboBox Value: Something 1";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)2;
            _row[1] = "ComboBox Value: Something 2";
            _dt.Rows.Add(_row);
            return _dt;
        }


I have checked for each control in panel1 to see if they exist and they do, the only thing is the controls and the panel are set to visible=false. If I set them to visible=true during the Displaying event, the value won't change to true. This indicates that the Telerik Control is blocking the ability to change the properties of the controls, espeically the ComboBox SelectedValue/SelectedIndex until the ToolWindow.DockState is no longer AutoHide

Kind Regards
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 10:26 AM
Hello Dan,

Please could you post your full designer and form1.cs file so I may try to replicate this. At the moment, the project doesn't run.
Thanks
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 10:44 AM
Form1.Designer.cs (C#)
namespace Sample
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radDock1 = new Telerik.WinControls.UI.Docking.RadDock();
            this.toolWindow1 = new Telerik.WinControls.UI.Docking.ToolWindow();
            this.radTreeView1 = new Telerik.WinControls.UI.RadTreeView();
            this.toolTabStrip2 = new Telerik.WinControls.UI.Docking.ToolTabStrip();
            this.toolWindow2 = new Telerik.WinControls.UI.Docking.ToolWindow();
            this.panel1 = new System.Windows.Forms.Panel();
            this.toolTabStrip1 = new Telerik.WinControls.UI.Docking.ToolTabStrip();
            this.documentContainer1 = new Telerik.WinControls.UI.Docking.DocumentContainer();
            ((System.ComponentModel.ISupportInitialize)(this.radDock1)).BeginInit();
            this.radDock1.SuspendLayout();
            this.toolWindow1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.toolTabStrip2)).BeginInit();
            this.toolTabStrip2.SuspendLayout();
            this.toolWindow2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.toolTabStrip1)).BeginInit();
            this.toolTabStrip1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.documentContainer1)).BeginInit();
            this.SuspendLayout();
            //
            // radDock1
            //
            this.radDock1.ActiveWindow = this.toolWindow1;
            this.radDock1.Controls.Add(this.toolTabStrip2);
            this.radDock1.Controls.Add(this.toolTabStrip1);
            this.radDock1.Controls.Add(this.documentContainer1);
            this.radDock1.DocumentManager.DocumentInsertOrder = Telerik.WinControls.UI.Docking.DockWindowInsertOrder.InFront;
            this.radDock1.IsCleanUpTarget = true;
            this.radDock1.Location = new System.Drawing.Point(9, 115);
            this.radDock1.MainDocumentContainer = this.documentContainer1;
            this.radDock1.Name = "radDock1";
            this.radDock1.Padding = new System.Windows.Forms.Padding(5);
            //
            //
            //
            this.radDock1.RootElement.MinSize = new System.Drawing.Size(25, 25);
            this.radDock1.RootElement.Padding = new System.Windows.Forms.Padding(5);
            this.radDock1.Size = new System.Drawing.Size(437, 317);
            this.radDock1.SplitterWidth = 4;
            this.radDock1.TabIndex = 0;
            this.radDock1.TabStop = false;
            this.radDock1.Text = "radDock1";
            //
            // toolWindow1
            //
            this.toolWindow1.Controls.Add(this.radTreeView1);
            this.toolWindow1.Location = new System.Drawing.Point(1, 24);
            this.toolWindow1.Name = "toolWindow1";
            this.toolWindow1.Size = new System.Drawing.Size(195, 281);
            this.toolWindow1.Text = "toolWindow1";
            //
            // radTreeView1
            //
            this.radTreeView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radTreeView1.Location = new System.Drawing.Point(0, 0);
            this.radTreeView1.Name = "radTreeView1";
            this.radTreeView1.Size = new System.Drawing.Size(195, 281);
            this.radTreeView1.TabIndex = 0;
            this.radTreeView1.Text = "radTreeView1";
            this.radTreeView1.SelectedNodeChanged += new Telerik.WinControls.UI.RadTreeView.RadTreeViewEventHandler(this.radTreeView1_SelectedNodeChanged);
            //
            // toolTabStrip2
            //
            this.toolTabStrip2.Controls.Add(this.toolWindow2);
            this.toolTabStrip2.Location = new System.Drawing.Point(5, 5);
            this.toolTabStrip2.Name = "toolTabStrip2";
            //
            //
            //
            this.toolTabStrip2.RootElement.MinSize = new System.Drawing.Size(25, 25);
            this.toolTabStrip2.SelectedIndex = 0;
            this.toolTabStrip2.Size = new System.Drawing.Size(197, 307);
            this.toolTabStrip2.TabIndex = 2;
            this.toolTabStrip2.TabStop = false;
            //
            // toolWindow2
            //
            this.toolWindow2.Controls.Add(this.panel1);
            this.toolWindow2.Location = new System.Drawing.Point(1, 24);
            this.toolWindow2.Name = "toolWindow2";
            this.toolWindow2.Size = new System.Drawing.Size(195, 281);
            this.toolWindow2.Text = "toolWindow2";
            //
            // panel1
            //
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(195, 281);
            this.panel1.TabIndex = 0;
            //
            // toolTabStrip1
            //
            this.toolTabStrip1.Controls.Add(this.toolWindow1);
            this.toolTabStrip1.Location = new System.Drawing.Point(206, 5);
            this.toolTabStrip1.Name = "toolTabStrip1";
            //
            //
            //
            this.toolTabStrip1.RootElement.MinSize = new System.Drawing.Size(25, 25);
            this.toolTabStrip1.SelectedIndex = 0;
            this.toolTabStrip1.Size = new System.Drawing.Size(197, 307);
            this.toolTabStrip1.TabIndex = 1;
            this.toolTabStrip1.TabStop = false;
            //
            // documentContainer1
            //
            this.documentContainer1.Location = new System.Drawing.Point(407, 5);
            this.documentContainer1.Name = "documentContainer1";
            //
            //
            //
            this.documentContainer1.RootElement.MinSize = new System.Drawing.Size(25, 25);
            this.documentContainer1.Size = new System.Drawing.Size(25, 307);
            this.documentContainer1.SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Fill;
            this.documentContainer1.SplitterWidth = 4;
            this.documentContainer1.TabIndex = 0;
            this.documentContainer1.TabStop = false;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(523, 441);
            this.Controls.Add(this.radDock1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radDock1)).EndInit();
            this.radDock1.ResumeLayout(false);
            this.toolWindow1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.radTreeView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.toolTabStrip2)).EndInit();
            this.toolTabStrip2.ResumeLayout(false);
            this.toolWindow2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.toolTabStrip1)).EndInit();
            this.toolTabStrip1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.documentContainer1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.Docking.RadDock radDock1;
        private Telerik.WinControls.UI.Docking.ToolWindow toolWindow1;
        private Telerik.WinControls.UI.RadTreeView radTreeView1;
        private Telerik.WinControls.UI.Docking.ToolTabStrip toolTabStrip2;
        private Telerik.WinControls.UI.Docking.ToolWindow toolWindow2;
        private System.Windows.Forms.Panel panel1;
        private Telerik.WinControls.UI.Docking.ToolTabStrip toolTabStrip1;
        private Telerik.WinControls.UI.Docking.DocumentContainer documentContainer1;
    }
}


Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace Sample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radTreeView1.Nodes.Add("Node 1");
            radTreeView1.Nodes.Add("Node 2");
            radTreeView1.Nodes.Add("Node 3");
 
            ComboBox _cmb1 = CreateCombo();
            _cmb1.SelectedValue = 1;
            this.Controls.Add(_cmb1);
 
        }
        private ComboBox CreateCombo()
        {
            ComboBox _cmb = new ComboBox();
            _cmb.Visible = true;
            _cmb.DataSource = CreateDataSource();
            _cmb.DisplayMember = "Display";
            _cmb.ValueMember = "Value";
            return _cmb;
        }
 
        private DataTable CreateDataSource()
        {
            //create datatable for combo datasource
            DataTable _dt = new DataTable("Data");
            _dt.Columns.Add("Value", Type.GetType("System.Int32"));
            _dt.Columns.Add("Display", Type.GetType("System.String"));
            DataRow _row = _dt.NewRow();
            _row[0] = (int)0;
            _row[1] = " -- Select --";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)1;
            _row[1] = "ComboBox Value: Something 1";
            _dt.Rows.Add(_row);
            _row = _dt.NewRow();
            _row[0] = (int)2;
            _row[1] = "ComboBox Value: Something 2";
            _dt.Rows.Add(_row);
            return _dt;
        }
 
        private void DisposeControls()
        {
            int _cnt = panel1.Controls.Count;
            for (int i = _cnt - 1; i > -1; i--)
            {
                Control _cntrl = panel1.Controls[i];
                panel1.Controls.Remove(_cntrl);
                _cntrl.Dispose();
 
            }
           
        }
 
        private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
        {
            DisposeControls();
            ComboBox _cmb1 = CreateCombo();
            _cmb1.Dock = DockStyle.Top;
            TextBox _txt1 = new TextBox();
            _txt1.Dock = DockStyle.Top;
 
            switch (radTreeView1.SelectedNode.Text)
            {
 
                case "Node 1":
                    panel1.Controls.Add(_cmb1);
                    _cmb1.SelectedValue = 1;
 
                    break;
                case "Node 2":
                    panel1.Controls.Add(_txt1);
                    _txt1.Text = "Hello World";
                    break;
                case "Node 3":
                    panel1.Controls.Add(_cmb1);
                    panel1.Controls.Add(_txt1);
                    _txt1.Text = "Hello World Again";
                    _cmb1.SelectedValue = 2;
 
                    break;
            }
        }
 
 
    }
}

0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 11:27 AM
Hello,

The issue seems to be with using a datasource on the combobox. If you can change it to...

private ComboBox CreateCombo()
{
    ComboBox _cmb = new ComboBox();
    _cmb.Visible = true;
    //_cmb.DataSource = CreateDataSource();
    //_cmb.DisplayMember = "Display";
    //_cmb.ValueMember = "Value";
    _cmb.Items.Add("--select--");
    _cmb.Items.Add("ComboBox Value: Something 1");
    _cmb.Items.Add("ComboBox Value: Something 2");
    return _cmb;
}

and
private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
    DisposeControls();
    ComboBox _cmb1 = CreateCombo();
    _cmb1.Dock = DockStyle.Top;
    TextBox _txt1 = new TextBox();
    _txt1.Dock = DockStyle.Top;
    switch (radTreeView1.SelectedNode.Text)
    {
        case "Node 1":
            panel1.Controls.Add(_cmb1);
            _cmb1.SelectedIndex = 1;
            break;
        case "Node 2":
            panel1.Controls.Add(_txt1);
            _txt1.Text = "Hello World";
            break;
        case "Node 3":
            panel1.Controls.Add(_cmb1);
            panel1.Controls.Add(_txt1);
            _txt1.Text = "Hello World Again";
            _cmb1.SelectedIndex = 2;
            break;
    }
}

then it seems to work fine. Please could you try this and let me know
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 11:41 AM
Hi Richard,

Thanks for your reply. This will work, however, it's not ideal as the DataSource is actually a DataTable coming from SQL. I'd have to loop through the DataTable and add each row's display value as a ComboBox item. Also, in my real application the Value isn't an int column, but a Guid. With using the .Items.Add, I lose the Guid value. I would have to create a new method, that takes the friendly display value,.Items.Add(string), and loop through my DataTable to find the matching display name and to get the Guid.

To me this seems like a work around, which isn't much different than using the AutoHideDisplayed event. Though, it does eliminate the issue of the split second of the ToolWindow being empty and then suddenly the controls appear that I get with AutoHideDisplayed.

Would be interesting to know why properties of a control can not be changed, eg (change .visible = true) when the ToolWindow.DockState = AutoHide.

I'll submit a support ticket. Thanks for your help!

Kind Regards.
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 12:00 PM
No problem. I'll look further into it (would be interested to know the result of your support ticket) but it looks like items aren't added when binding to a datasource under this condition.

Let me know if I can help further
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 12:33 PM
Hi Richard

Interestingly, I can't help but wonder, if the panel1 that the ComboBox control gets added to, is somehow removed or detached from the ToolWindow and doesn't get added back to the ToolWindow until it is fully displayed.

I say this because if you add a ComboBox at runtime then set the SelectedValue/SelectedIndex then add the ComboBox to the form the SelectedValue remains null (SelectedIndex throws an exception error). However, if you set the SelectedValue after adding the control to the form, it's fine.

Perhaps the Telerik control does something behind the scenes that maybe creates a new ToolWindow, but hasn't actually attached the current ToolWindow and/or all the controls to it until it is fully displayed. This would help explain why the SelectedValue can't be set when the DockState = AutoHide as the control isn't actually attached to anything physically on the form. Likewise, would also help explain why the SelectedValue can't be set in the AutoHideWindowDisplaying event but can be in the AutoHideWindowDisplayed event.

Although, doesn't quite explain why the controls properties (eg .visible = true) can't be changed when the DockState=AutoHide. These remain visible = false in the AutoHideWindowDisplaying event and don't change to visible = true until the AutoHideWindowDisplayed event.

I'll let you know what I hear from Telerik. Perhaps it's a slight bug being caused by windows standard behaviour as noted above.

Cheers
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 01:21 PM
Hi again Dan,

Please could you try this..

private ComboBox CreateCombo()
{
    ComboBox _cmb = new ComboBox();
    _cmb.Visible = true;
    _cmb.DataSource = CreateDataSource();
    _cmb.DisplayMember = "Display";
    _cmb.ValueMember = "Value";
    _cmb.BindingContext = this.BindingContext; // ADDITIONAL LINE
    return _cmb;
}

Let me know if that helps
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 05:16 PM
Hi Richard

That's working, Thanks!  I feel quite silly for not thinking of that before. I think mainly, because it works fine without it in the other DockStates.  Just to note, in case anyone else creates their controls in a separate static class as I do.... you will need to pass the form's BindingContext into the static class.  eg:
public static class ControlManager
    {
  private static Panel _pnlPropertyControls;
  private static BindingContext _bindingContext;
 public static void InitializeControlManager(Panel CntrlParentContainer, BindingContext CntrlBindingContext)
        {
    
          _pnlPropertyControls = CntrlParentContainer;
          _bindingContext = CntrlBindingContext;
         
        }
 
  private static ComboBox CreateComboBox()
        {
            ComboBox _cmb = new ComboBox();
             _cmb.DataSource = CreateDataSource();
            _cmb.ValueMember = "Value";
            _cmb.DisplayMember = "Display";
            _cmb.Visible = true;
            _cmb.BindingContext = _bindingContext;
            return _cmb;
        }
}

Unfortunately.......... Now, I have a new issue that I didn't have previously with the ToolWindow.DockState = AutoHide.
If the ToolWindow is in a visible DockState (eg Dockable) controls are drawn in the correct order. If the DockState = AutoHide the controls tend to appear randomly. Example: Where I had Label, TextBox, Label,TextBox, it now returns Label, Label, TextBox, TexBox. It doesn't always seem to do this, so it's difficult to pinpoint what's causing it.

I can't seem to reproduce in my sample application. Although, in the sample, I've only created 2 basic controls. I'm currently going through my code to see if I have done something, but nothing seems to stand out. 

Any possible ideas by chance? I haven't heard from Telerik as yet, so perhaps they'll add some light to it in the support ticket.

Cheers
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 05:28 PM
Hello Dan,

Glad that worked for you. Please remember to mark as answer too. It's also worth letting telerik know in your support ticket (if you haven't already) that you have a solution for that part as it may mean you get a quicker response on other issues you reported.

As  per your other issue, I haven't been able to replicate it either at the moment. If you can replicate it in a test project, then again, let me know and I'll try it too. I'll have some more attempts to replicate it for you here though and see what I come up with and let you know if I can replicate it and come up with an answer.

Thanks
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 05:50 PM
Hello again dan,

I've managed to reproduce this in your test project using the following code.
private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
    DisposeControls();
    TextBox _txt1 = new TextBox(); // TEXT 1
    _txt1.Dock = DockStyle.Top;
    ComboBox _cmb1 = CreateCombo(); // CMB 1
    _cmb1.Dock = DockStyle.Top;
    TextBox _txt2 = new TextBox(); // TEXT 2
    _txt2.Dock = DockStyle.Top;
    switch (radTreeView1.SelectedNode.Text)
    {
        case "Node 1":
            //panel1.Controls.Add(_cmb1);
            //_cmb1.SelectedIndex = 1;
             panel1.Controls.Add(_cmb1);
            panel1.Controls.Add(_txt1);
            _txt1.Text = "Hello World 1";
            _cmb1.SelectedIndex = 2;
            break;
        case "Node 2":
            panel1.Controls.Add(_txt1);
            _txt1.Text = "Hello World";
            break;
        case "Node 3":
            panel1.Controls.Add(_cmb1); // CMB 1
            panel1.Controls.Add(_txt1); // TEXT 1
            _txt1.Text = "Hello World Again";
            _cmb1.SelectedIndex = 2;
            panel1.Controls.Add(_txt2); // TEXT 2
            // Comes out as TEXT,TEXT,COMBO
            break;
    }
}

I will look into this and get back to you as soon as I can
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 20 Jan 2011, 06:07 PM
Hi Richard

The reason it comes out as Text, Text, Combo is because of the order the controls were added with the DockState = Top. The hierarchy/Z order of the controls added to the panel = Combo, Text, Text, but with DockTop it pushes the next control to the top, thus leaving the last control being added at the top of the Dock.

In my case, I create the Label, Combo, Label, Text, Label, Text and use the .BringToFront() on the ControlAdded event for the panel1. In my real application this works perfectly when the DockState = Dockable. But when the DockState = AutoHide and I switch nodes I sometimes end up with the correct order and other times I end up with the controls in various orders like: Label, Label, Text, Combo,Label, Text. Even though I am creating the controls in the exact same order.

Cheers
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 06:10 PM
Hi,

Yes you're right. I've just realised that.
I'll let you know if I can replicate it properly.
Regards,
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 21 Jan 2011, 09:42 AM
When I create/add the controls to the ToolWindow, I set them in a specific z-order.At the end of my method, I doubled to make sure the controls were still in the same order, and they were.  IF the ToolWindow.DockState = AutoHide when I create/add the controls the AutoHide state seems to re-ordering the controls. I checked the z-order in the AutoHideWindowDisplaying event and my controls were no longer in the same z-order. On a good note, I was able to reset the indexes. I'll need to do further testing to make sure the indexes continue to stay as they are.

0
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 09:56 AM
Morning Dan,

Does this mean that you have a workaround by re-setting the z-order of the controls in that panel?
Regards,
Richard
0
Dan Foster
Top achievements
Rank 2
answered on 21 Jan 2011, 06:10 PM
Hi Richard

I've done some testing and seems to be working ok now. I've had to create a List<Control> that contains a copy of the controls that are added to the ToolWindow. If the DockState = AutoHide when the controls are added to the window, the z-order of the child controls gets over written, presumably somewhere in the dock window. I don't get an issue if the DockState = Dockable or Tabbed; the original z-order remains intact. 

In the AutoHideWindowDisplaying event, I reset the child indexes.
eg:
for(int _i = 0; _i < _cntrlListZedOrder.Count; _i++)
               {
                   //find the correct index in the list and reset
                   Control _cntrl = _cntrlListZedOrder[_i];        
                   panel1.Controls.SetChildIndex(_cntrl, _i);
                   
               }

I received a response from Telerik regarding the ComboBox issue and apparently it's due to the  synchronization of the BindingContext. " In this situation the ComboBox control can not update its SelectedValue - the control is added to an invisible window hosted in the AutoHide window."

I don't recall ever having to set the parent control (eg panel) to visible in order to set a combobox value, but then perhaps with previous applications I haven't actually tested or come across this specific issue (non Telerik controls).

You've been a great help, thanks!



0
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 06:13 PM
Hi Dan,

I'm glad that you have it sorted. Apologies I couldn't help you all the way through it but I'm glad I was of some help to you.
All the very best
Richard
Tags
Dock
Asked by
Dan Foster
Top achievements
Rank 2
Answers by
Richard Slade
Top achievements
Rank 2
Dan Foster
Top achievements
Rank 2
Share this question
or