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

Cell to accept only numbers?

Hi, My grouping grid has a cell that is of CellType = "ComboBox". This cell is later cast to a GridComboBoxCellRenderer so that a datasource can be assigned to achieve an auto-complete effect. The datasource contains only integers. How can I prevent the user from entering non-numeric into that cell? I tried using TableControlCurrentCellValidateString but I couldnt get the desired affect. Thanks, Kav

1 Reply

AD Administrator Syncfusion Team July 13, 2006 12:12 PM UTC

Hi Kav, When the GridDropDownStyle is set to AutoComplete, the user input is restricted to items from the ChoiceList or DataSource but the user can type text into the text box and the text box will be filled only with a matching choice. (Or) In an AutoComplete cell, you cant type in anything other than the content that is in the datasource or choicelist. You can use the code below to prevent the user from entering a non-numeric values, if the GridDropDownStyle is set to Editable. GridCurrentCell cc = this.gridGroupingControl1.TableControl.CurrentCell; if(cc.Renderer.StyleInfo.CellType == "ComboBox") { try { int val = int.Parse(e.Inner.Text); } catch { MessageBox.Show("Invalid entry"); e.Inner.Cancel = true; } } FYI, the other dropdownstyles, GridDropDownStyle.Editable and GridDropDownStyle.Exclusive are explained below. 1) GridDropDownStyle.Editable : When you set Editable, any thing can be typed. User can edit the textbox contents and is not limited to the values in the existing choices. 2. GridDropDownStyle.Exclusive does not allow the user to edit. Input is restricted to items from the ChoiceList or DataSource. Let me know if you need any further assistance. Regards, Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon