Home Forums WinForms controls Xceed Grid for WinForms Dismissing ComboBox in CellEditorManager

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15733 |

    Hi,

    I’ve got a CellEditorManager that controls editing of grid cells. Some cells are editable, some are not — all are selectable. Those cells that are editable have ComboBox dropdowns that appear when edit mode is invoked.

    The CellEditorManager always creates a ComboBox (based on the Slider example.) I would like a way to interrogate the cell and based on the cell value — completely avoid display of the ComboBox. Here’s what I’ve tried

    In SetControlValueCore() I tried control.Dispose() but this lead to unhandled exceptions.
    In SetControlValueCore() I tried control.Hide() and control.Visible = false (I’m guessing they’re the same) and this works somewhat but the cell background color does not repaint — the control doesn’t really go away until I click another cell.

    So in essence, I’d like a way to say “there’s no dropdown to show” and give the impression that the cell is read-only (but setting the cell to read-only is not an option because it then no longer allows selection.)

    Imported from legacy forums. Posted by camera (had 2853 views)

    User (Old forums)
    Member
    Post count: 23064

    *cough*

    Imported from legacy forums. Posted by camera (had 313 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m not sure I totally understand your issue, because the cell should still be selectable even though it is ReadOnly, but in any case, you can try to hide the dropdown control itself, and control the edition of the value in the editor TextBoxArea. You need to use the EnteringEdit event of the cell to do this. Here is the code you could use :

    //assuming the following at form_load, on column 0:
    <code> dataRowTemplate1.Cells[ 0 ].EnteringEdit += new EnteringEditEventHandler( Form1_EnteringEdit );

    ComboBoxEditor cboEditor = new ComboBoxEditor();
    cboEditor.DataSource = view;
    cboEditor.ValueMember = “SupplierID”;
    cboEditor.DisplayFormat = “%SupplierID%”;
    cboEditor.ActivatingControl += new CellEditorEventHandler( cboEditor_ActivatingControl );
    cboEditor.DeactivatingControl += new CellEditorEventHandler( cboEditor_DeactivatingControl );
    gridControl1.Columns[ “SupplierID” ].CellEditorManager = cboEditor;
    </code>
    ,

    //What you need to do in the event handlers
    <code> void Form1_EnteringEdit( object sender, EnteringEditEventArgs e )
    {
    ( ( WinComboBox )e.CellEditorManager.TemplateControl).DropDownControl.Visible = false;
    ( ( WinComboBox )e.CellEditorManager.TemplateControl).DropDownButton.Visible = false;
    }

    void cboEditor_ActivatingControl( object sender, CellEditorEventArgs e )
    {
    ( ( WinComboBox )e.Control ).TextBoxArea.ValidatingText += new ValidatingTextEventHandler( TextBoxArea_ValidatingText );
    }

    void TextBoxArea_ValidatingText( object sender, ValidatingTextEventArgs e )
    {
    //will prevent the user from changing the value of the cell
    e.Valid = false;
    }

    void cboEditor_DeactivatingControl( object sender, CellEditorEventArgs e )
    {
    //need to unsubscribe because it gets subscribed to every time the editor is activated
    ( ( WinComboBox )e.Control ).TextBoxArea.ValidatingText -= new ValidatingTextEventHandler( TextBoxArea_ValidatingText );
    }
    </code>

    Imported from legacy forums. Posted by André (had 423 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, Andre. Perhaps I set IsSelectable = false and ReadOnly = true at the same time and associated the non-selectability with both of them (incorrectly, as you’ve stated above.)

    My solution was to detect that there was nothing to drop down a EnteringEdit() method and then avoid showing the editor at all with the line grid.CurrentCell.LeaveEdit(false).

    Imported from legacy forums. Posted by camera (had 4087 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.