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

Handle combo box control

Hi,

Q1) How i can set a default value for combo box in add new record row.

Q2) There are 2 combobox type columns available in my GCC.I need to show/hide second combobox according to first combobox value.
How i can do this when i change the first combobox value.It is better if i can implement it within TableControlCurrentCellCloseDropDown event.
Image URL : combo box image

Thanks & Regards,
Sumudu EKanayake

1 Reply

NK Neelakandan Kannan Syncfusion Team August 22, 2016 09:45 AM UTC

Hi Sumudu, 

Thanks for using Syncfusion products. 

Query 
How i can set a default value for combo box in add new record row. 

The reported scenario can be achieved by using the ShowDefaultValuesInAddNewRecord property and setting the default values for each columns using the Fields[“ColumnName”].DefaultValue property. Please make use of the below code, 
 
Code snippet 
this.gridGroupingControl1.ShowDefaultValuesInAddNewRecord = true; 
this.gridGroupingControl1.TableDescriptor.Fields["CategoryName"].DefaultValue = "Category12345"; 
this.gridGroupingControl1.TableDescriptor.Fields["Description"].DefaultValue = "Sample2"; 
this.gridGroupingControl1.TableDescriptor.Fields["CategoryID"].DefaultValue = "Sample1"; 
this.gridGroupingControl1.TableDescriptor.Fields["SampleData"].DefaultValue = "SampleData12345"; 
 
Query 
How I can do this when I change the first combobox value.It is better if I can implement it within TableControlCurrentCellCloseDropDown event. 


The reported scenario can be achieved by handling the QueryCellStyleInfo event. Here we have provided the sample in which “CategoryID” column combobox will be set to hide when “Description” column’s value is “Sample2”. Please make use of the below code, 

Code snippet 
this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity != null && e.TableCellIdentity.Column != null 
        && e.TableCellIdentity.Column.Name == "CategoryID" 
        && e.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.Record) 
    { 
 
        //Checks if the "Description" column is having value "Sample2" 
        if (e.TableCellIdentity.DisplayElement.GetRecord().GetValue("Description").ToString() == "Sample2") 
        { 
            //Hiding the ComboBox dropdown button 
            e.Style.ShowButtons = GridShowButtons.Hide; 
        } 
    } 
} 
 
 

Screenshot 
 

Sample 

Regards, 
Neelakandan 


Loader.
Up arrow icon