Home Forums WinForms controls Xceed Grid for WinForms Dismiss ComboBox Upon Selection Reply To: Dismiss ComboBox Upon Selection

User (Old forums)
Member
Post count: 23064

I see three solutions. First, make the cell leave edition once the user has made his selection. Second hide the dropdown button, but then, the user will not be able to drop the control again, until you show the button again. Third, increase the width of the column while a cell in that column is in edition, and reset it to its original size as soon as the cell leaves edition.

Here is the code for the first solution :
<code> void cboEditor_ActivatingControl( object sender, CellEditorEventArgs e )
{
( ( WinComboBox )e.Control ).DroppedDownChanged += new EventHandler( Form1_DroppedDownChanged );
}

void Form1_DroppedDownChanged( object sender, EventArgs e )
{
if( !( ( WinComboBox )sender ).DroppedDown )
{
gridControl1.CurrentCell.LeaveEdit( true );
}
}

void cboEditor_DeactivatingControl( object sender, CellEditorEventArgs e )
{
//need to unsubscribe because it gets subscribed to every time the editor is activated
( ( WinComboBox )e.Control ).DroppedDownChanged -= new EventHandler( Form1_DroppedDownChanged );
}
</code>
¨
Here is the code you can use for the third solution :
<code> private static int origninalWidth = 0;

void Form1_EnteringEdit( object sender, EnteringEditEventArgs e )
{
origninalWidth = ( ( DataCell )sender ).ParentColumn.Width;
( ( DataCell )sender ).ParentColumn.Width = origninalWidth + 20;
}

void Form1_LeavingEdit( object sender, LeavingEditEventArgs e )
{
( ( DataCell )sender).ParentColumn.Width = origninalWidth;
}
</code>
¨
You can combine the two if you want.

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