Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Editors per cell in an UltraTree
posted

Hi there,

I have some difficulties to use editors in an ultra tree. I would like to create a tree just like the PropertyGrid, so I would like to have different data type in the cells (String, Integer, Boolean, Color, Font etc..)

I succedded with the string, the font, the combo but I have problems with the colorpicker (I have the color but it's not editable) and also with the CheckEditor (I can't check/uncheck)

Remark: If I set DataType=typeof(Color) for a colum it works well. But since I want to have different type in the cells I can't do that.

Thanks for your help.

Here is my sample code:

-------------------------------------------------------------

using System;
using System.Drawing;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinTree;
using Infragistics.Win.UltraWinEditors;

namespace InfragisticEditors
{
    public partial class Form1 : Form
    {
        private UltraTreeNodeColumn _colName;
        private UltraTreeNodeColumn _colValue;

        public Form1()
        {
            InitializeComponent();

            InitTree();
        }

        private void InitTree()
        {
            // Clear nodes:
            this.ultraTree1.Nodes.Clear();

            // set outlook view style:
            this.ultraTree1.ViewStyle = ViewStyle.OutlookExpress;
            this.ultraTree1.Indent = 10;

            // Editable cells:
            this.ultraTree1.Override.CellClickAction = CellClickAction.EditCell;
       
            // Only allow one node to be selected at a time
            this.ultraTree1.Override.SelectionType = SelectType.Single;

            // Use single-pixel borders of 'Control' color for the cells
            this.ultraTree1.ColumnSettings.BorderStyleCell = UIElementBorderStyle.Solid;
            this.ultraTree1.ColumnSettings.CellAppearance.BorderColor = SystemColors.Control;

            // Hide the headers:
            this.ultraTree1.ColumnSettings.LabelPosition = NodeLayoutLabelPosition.None;

            // Add colums:
            UltraTreeColumnSet rootColumnSet = this.ultraTree1.ColumnSettings.RootColumnSet;
            _colName = rootColumnSet.Columns.Add("Name");
            _colName.DataType = typeof(string);
            _colName.LayoutInfo.PreferredCellSize = new Size(this.ultraTree1.Width / 2, 0);

            _colValue = rootColumnSet.Columns.Add("Value");
            _colValue.DataType = typeof(object);
            _colValue.LayoutInfo.PreferredCellSize = new Size(this.ultraTree1.Width / 2, 0);
            _colValue.AllowCellEdit = AllowCellEdit.Full;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Add a text node:
            String str = "Hello world";
            UltraTreeNode node1 = this.ultraTree1.Nodes.Add(null, "");
            node1.SetCellValue(_colName, "String");
            node1.SetCellValue(_colValue, str);

            // Add a color:
            Color color = Color.FromArgb(255, 0, 0);
            UltraTreeNode node2 = this.ultraTree1.Nodes.Add(null, "");
            node2.Cells[_colValue].Editor = new ColorPickerEditor();
            node2.SetCellValue(_colName, "Color");
            node2.SetCellValue(_colValue, color);

            // Add a combo
            UltraComboEditor editorControl = new UltraComboEditor();
            UltraTreeNode node3 = this.ultraTree1.Nodes.Add(null, "");
            editorControl.Items.Add("True");
            editorControl.Items.Add("False");
            editorControl.DropDownStyle = DropDownStyle.DropDownList;
            node3.Cells[_colValue].EditorControl = editorControl;
            node3.SetCellValue(_colName, "Combobox");
            node3.SetCellValue(_colValue, false);

            // Add a checkbox:
            UltraTreeNode node4 = this.ultraTree1.Nodes.Add(null, "");
            node4.Cells[_colValue].Editor = new CheckEditor();
            node4.SetCellValue(_colName, "Checkbox");
            node4.SetCellValue(_colValue, false);

            // Add a collection
            UltraTreeNode node5 = this.ultraTree1.Nodes.Add(null, "");
            EditorWithText textEditor = new EditorWithText();
            node5.Cells[_colValue].Editor = textEditor;
            EditorButton editorButton = new EditorButton("ellipsis");
            editorButton.Text = "...";
            //editorButton.Click += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(editorButton_Click);
            textEditor.ButtonsRight.Add(editorButton);
            node5.Cells[_colValue].AllowEdit = AllowCellEdit.ReadOnly;
            node5.SetCellValue(_colName, "Button");
            node5.SetCellValue(_colValue, "(Collection)");

            // Add a font:
            Font font = new Font("Arial", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            UltraTreeNode node6 = this.ultraTree1.Nodes.Add(null, "");
            node6.Cells[_colValue].Editor = new FontNameEditor();
            node6.SetCellValue(_colName, "Font");
            node6.SetCellValue(_colValue, font);
        }
    }
}