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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridControl ComboBox only allow items in ChoiceList

Thread ID:





120719 Oct 8,2015 05:20 AM UTC Oct 13,2015 11:29 AM UTC WinForms 6
Tags: GridControl
Asked On October 8, 2015 05:20 AM UTC

I have a ComboBox in a GridControl. I set the items for the dropdown by assigning a ChoiceList.

How can I restrict the entries in that particular cell so that the only allowed values are the ones in the ChoiceList and the user cannot enter text from the keyboard? 

So basically I'm looking for ComboBoxStyle.DropDownList functionality but for a ComboBox in a GridControl cell: https://msdn.microsoft.com/en-us/library/system.windows.forms.comboboxstyle.aspx

Replied On October 8, 2015 04:53 PM UTC

I figured it out:
gridControl1[row, col].DropDownStyle = GridDropDownStyle.Exclusive;

Solai A L [Syncfusion]
Replied On October 9, 2015 12:31 PM UTC

Hi Taylour,

Thank you for your interest in Syncfusion products.

You can restrict the editing of combo box cell by using the following code. Please refer the below sample and code for reference.

Code :

gridControl1[2, 3].CellType = "ComboBox";

            //Set datasource for the combobox  cell

gridControl1[2, 3].DataSource = items;

gridControl1[2, 3].CellValue = "Five";

gridControl1[2, 3].ExclusiveChoiceList = true;

gridControl1[2, 3].ReadOnly = true;

Sample :

Thanks & Regards,

Replied On October 9, 2015 03:34 PM UTC

Hi AL.Solai., thanks for your help.

There is a problem with your sample code in that by adding ReadOnly = true, you can't change the value of the ComboBox using the mouse (note that your second example in cell 2,4 also doesn't show up because you have ReadOnly set to true before setting the cell value). If we don't set ReadOnly to true, then the user can highlight the cell and press the delete key to delete the cell value.
Is there any way around this?

Also the documentation (in Intellisense) for ExclusiveChoiceList says to use DropDownStyle instead. I assume DropDownStyle = GridDropDownStyle.Exclusive is equivalent?

Solai A L [Syncfusion]
Replied On October 12, 2015 12:23 PM UTC

Hi Taylour,

Thank you for your update.

To restrict adding data from the Combo box, use the following two properties.
Code :

// User input is restricted to datasource/choicelist. 

gridControl1[2, 3].ExclusiveChoiceList = true;

// User input is Restricted to items from datasource/choicelist.

gridControl1[2, 3].DropDownStyle = GridDropDownStyle.Exclusive;


Replied On October 12, 2015 04:53 PM UTC

Hi, the two lines of code you provided were not enough as they do not handle the case when the user presses the delete or backspace key which allows empty values in the cell. I added these two events and suppressed the keys to get the effect I wanted to achieve.

        void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
            if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
                e.Handled = true;

        void gridControl1_KeyDown(object sender, KeyEventArgs e)
            if (e.KeyCode == Keys.Delete)
                e.Handled = true;

Solai A L [Syncfusion]
Replied On October 13, 2015 11:29 AM UTC

Hi Taylour,

Thank you for your update.

The given properties will restrict the user from adding the input to combo box choice list / data source. The data given by the user will be temporarily viewed (it will not be updated in the combo box). Finally, we are glad that the requirement has been achieved.

Thanks & Regards, 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon