Home Forums WinForms controls Xceed Grid for WinForms Dismissing ComboBox in CellEditorManager Reply To: Dismissing ComboBox in CellEditorManager

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)