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
685
Edit with Dropdown
posted

I need to edit a cell and when it enters edit mode, I need it to show a dropdown with values that come from a DB.

I can create the dropdown, and it populates, and the dropdown even shows in the cell.  But when I click on the dropdown, nothing happens.

I don't know if it's that the cell's not expanding to show me the values, or if the values are somehow not making it to the cell.

        private void ROGridServerDBs_AfterEnterEditMode(object sender, EventArgs e)
        {
            UltraDropDown drop = new UltraDropDown();
            string column = new GridInfo().GetActiveCellName(ROGridServerDBs);
            if (column == "ServerRole")
            {
                string query = new MEQueries().AppRolesGet();
                UltraGridCell activeCell = ROGridServerDBs.ActiveCell;
                MinionConn mc = new MinionConn();
                drop.DataSource = mc.RunQuery(query);
                drop.ValueMember = "AppRoleName";
                drop.DisplayMember = "AppRoleName";
                activeCell.ValueList = drop;
                activeCell.Refresh();
            }
        }

Parents
  • 1560
    Offline posted

    Hello Sean,

    Thank you for the code-snippet you have provided.

    What I noticed is that you are creating and assigning the UltraDropDown control inside of AfterEnterEditMode. However, once the cell has entered edit mode, it's using a default text editor instead of the UltrDropDown and this is the reason why it can not be opened.


    My suggestion to achieve your requirement is to assign the UltraDropDown to the cell in InitializeLayout event. This will ensure that the drop down will be assigned to the cell before it enters edit mode.

     private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
    
                this.ultraGrid1.DisplayLayout.Bands[0].Columns.Add("DropDownColumn", "DropDown Column");
                e.Layout.Bands[0].Columns["DropDownColumn"].ValueList = ultraDropDown1;
    
            }
    

    Afterwards, AfterEnterEditMode event can be handled to drop it down.

    private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e)
            {
                var grid = (UltraGrid)sender;
                grid.BeginInvoke(new MethodInvoker(this.DropDownGridCellListIfNeeded));
            }
    
    private void DropDownGridCellListIfNeeded()
            {
                var grid = this.ultraGrid1;
                var activeCell = grid.ActiveCell;
                if (null == activeCell || activeCell.DroppedDown)
                    return;
    
                var editor = activeCell.EditorResolved as EditorWithCombo;
                if (null == editor)
                    return;
    
                activeCell.DroppedDown = true;
            }          

    Sample application, that uses the approach from above can be found here.

    If you require any further assistance on the matter, please let me know.


    Sincerely,

    Teodosia Hristodorova
    Associate Software Developer



Reply Children