Make a combobox non editable

In certain circumstances I want to make a combobox not editable.

Currently I do something like:

GridTableCellStyleInfo csi = gtd.Columns[rf.FieldName].Appearance.AnyRecordFieldCell;

csi.ReadOnly = false;
csi.CellType = "ComboBox";
csi.DropDownStyle = GridDropDownStyle.Exclusive;

But the user can still click the drop down button and see the other selections (but can't select a new one). Is there a way to prevent the user from seeing the other selections?


3 Replies

JJ Jisha Joy Syncfusion Team November 8, 2010 05:33 AM UTC

Hi David,

To cancel showing the dropdownlist for read-only cells, you can handle the TableControlCurrentCellShowingDropDown event as shown below:

// Event Handler
this.gridGroupingControl1.TableControlCurrentCellShowingDropDown += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellShowingDropDownEventHandler(gridGroupingControl1_TableControlCurrentCellShowingDropDown);

// Method Invoked
void gridGroupingControl1_TableControlCurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex);
if (cc.Renderer is GridComboBoxCellRenderer && style.ReadOnly)
{
GridComboBoxCellRenderer rend = cc.Renderer as GridComboBoxCellRenderer;
rend.ListBoxPart = null;
}
}

Regards,
Jisha



DM David Mecteaux November 12, 2010 03:55 PM UTC

Thank you Jisha,

That worked quite nicely.



JJ Jisha Joy Syncfusion Team November 15, 2010 05:35 AM UTC

Hi David,

Thank you for your update.

Regards,
Jisha


Loader.
Up arrow icon