Skip to main content Skip to footer

Creating Cascading Dropdownlists in C1TrueDBGrid

Cascading dropdown lists can be a generic requirement when it comes to grids. Cascading dropdown means that the contents of one of the dropdown is dependent on the selection made in the other dropdown. MS Excel implements these cascading dropdowns with the help of validation rules. This blog discusses how the similar concept can be implemented in C1TrueDBGrid on the basis of DataView filtering. Here is how it works: Demo1

Implementation

We create two different datasources. One having just one column that represents the options to be displayed in the first C1TrueDBDropDown. The second datasource would be having two columns, one representing the data to be displayed in the second C1TrueDBDropDown and the other containing the data of the first C1TrueDBDropDown. Based on the user selection, we would apply filtering to the DataView of the second C1TrueDBDropDown. Hence, it would display only specific items in the second C1TrueDBDropDown .


private void c1TrueDBDropdown2_DropDownOpen(object sender, EventArgs e)  
 {  
    scountry = c1TrueDBGrid1[c1TrueDBGrid1.Row, 1].ToString();  
    if (scountry == "France")  
    {  
       DataView dv = (DataView)c1TrueDBDropdown2.DataSource;  
       dv.RowFilter = "Country = 'France'";  
       c1TrueDBDropdown2.DataSource = dv;  
       c1TrueDBDropdown2.ValueMember = dv.Table.Columns[1].ColumnName;  
    }  
    else if (scountry == "America")  
    {  
       DataView dv = (DataView)c1TrueDBDropdown2.DataSource;  
       dv.RowFilter = "Country = 'America'";  
       c1TrueDBDropdown2.DataSource = dv;  
       c1TrueDBDropdown2.ValueMember = dv.Table.Columns[1].ColumnName;  
    }  
 }  

Refer to the samples for complete implementation. Download C# Sample Download VB Sample

MESCIUS inc.

comments powered by Disqus