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
EditorWithText cannot cancel editing cell
posted

Hi there,

I created a small test where I'm using an UltraTree with cells. I would like to cancel the edit mode if the text is equal to "foo". In this case I set e.Cancel to true but it doesn't seems to work.

Here is my test code:

    public partial class Form1 : Form
    {
        UltraTreeNodeColumn _colName = null;
        UltraTreeNodeColumn _colValue = null;

        UltraTreeNode _node1 = null;

        public Form1()
        {
            InitializeComponent();
            InitTree();
            InitValues();
        }

        private void InitTree()
        {
            UltraTreeColumnSet rootColumnSet = this.ultraTree1.ColumnSettings.RootColumnSet;

            this.ultraTree1.Override.CellClickAction = CellClickAction.EditCell;

            //    Use the 'OutlookExpress' ViewStyle; reduce indentation a little
            this.ultraTree1.ViewStyle = ViewStyle.OutlookExpress;
            this.ultraTree1.Indent = 10;

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

            _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;

            //    Auto-fit columns
            this.ultraTree1.ColumnSettings.AutoFitColumns = AutoFitColumns.ResizeAllColumns;
        }

        private void InitValues()
        {
            _node1 = ultraTree1.Nodes.Add("key1");

            _node1.SetCellValue(_colName, "Text1");

            _node1.SetCellValue(_colValue, "Value1");
           
            UltraTreeNodeCell cell1 = _node1.Cells[_colValue];
            cell1.Editor = new EditorWithText();
            cell1.Editor.Tag = _node1;
            cell1.Editor.BeforeExitEditMode += new BeforeExitEditModeEventHandler(Editor_BeforeExitEditMode);
        }

        void Editor_BeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e)
        {
            EditorWithText editor = sender as EditorWithText;
            if (editor != null)
            {
                if (editor.CurrentEditText.Equals("foo"))
                {
                    MessageBox.Show("Invalid");
                    e.Cancel = true;
                }
            }
        }
    }

Thanks for your help...

Parents
  • 69832
    Verified Answer
    Offline posted

    Strictly speaking, that is a bug - UltraTree handles the editor's BeforeExitEditMode event as well, and it is not checking the value of e.Cancel in its handler before proceeding. What you should do is handle UltraTree's BeforeCellExitEditMode event instead...you can do the same thing therein, the only difference being that the sender in that case will be the UltraTree. You can get the editor from the e.Cell.EditorResolved property.

Reply Children
No Data