We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Deleting combobox text

I am trying to prevent the user from deleting the text in a combobox. The style is autocomplete, exclusive is set to true, but the user can still select the text inside and delete it using the delete key, backspace key, or any combination of these keys with control, alt, shift key. The CurrentCellDeleting event doesn't seem to trap this.

Also, if you put control inside the combobox and hit Control+Delete, the entire combobox disappears. How do i prevent this as well.

I am using the GridControl, version 5.2.0.25

Thanks,
Julie


1 Reply

JJ Jisha Joy Syncfusion Team January 12, 2009 06:58 AM UTC

Hi Julie,

We appreciate your interest in Syncfusion products.

The mentioned issues can be avoided by handling CurrentCellDeleting and CurrentCellKeyDown events. Please see the code:


this.gridControl1.CurrentCellDeleting += new CancelEventHandler(gridControl1_CurrentCellDeleting);
this.gridControl1.CurrentCellKeyDown += new KeyEventHandler(gridControl1_CurrentCellKeyDown);


void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
bool ctl = (e.KeyData & Keys.Control) != 0;

bool del = (e.KeyData & Keys.Delete) != 0;

if (ctl && del) // Check for CTRL+del
{
e.Handled = true;
}
}



void gridControl1_CurrentCellDeleting(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "ComboBox")
{
e.Cancel = true;
}
}

Regards,
Jisha


Loader.
Live Chat Icon For mobile
Up arrow icon