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

Cascading Combobox sample needed

Thread ID:

Created:

Updated:

Platform:

Replies:

141487 Dec 13,2018 07:20 PM UTC Dec 17,2018 07:22 AM UTC WinForms 3
loading
Tags: SfDataGrid
Tim Larson
Asked On December 13, 2018 07:20 PM UTC

I am trying to use the sfDataGrid and create a simple combobox of Country the user will select the country and then the next combobox will be a dropdown of the states for each country.
I am tring to populate the combox values from a datatable and I keep getting the key already exists.

Please provide a simple example of above using a datatable.

Thanks,
Tim

Jayaleshwari N [Syncfusion]
Replied On December 14, 2018 11:57 AM UTC

Hi Tim, 
 
Thanks for using Syncfusion Products. 
 
We have checked the reported query “Change the items source of combo box column based on another combo box column value” from our side. You can achieve your requirement by using IDataSourceSelector property of the GridComboBoxColumn.  
 
Code Example : IDataSourceSelector implementation and assigned to GridComboBoxColumn. 
  
public Form1() 
{ 
    InitializeComponent(); 
    this.sfDataGrid.Columns.Add(new GridComboBoxColumn() { MappingName = "State", DisplayMember = "State", ValueMember = "State", IDataSourceSelector = new CustomSelector() }); 
} 
 
public class CustomSelector : IDataSourceSelector 
{ 
    DataTable statesOfUS; 
    DataTable statesOfBrazil; 
 
    public CustomSelector() 
    { 
        statesOfBrazil = GetStatesOfBrazil(); 
        statesOfUS = GetStatesOfUS(); 
    } 
 
    public IEnumerable GetDataSource(object record, object dataSource) 
    { 
        if (record == null) 
            return null; 
 
        var data = record as DataRowView; 
        var countryName = data.Row["Country"].ToString(); 
 
        if (countryName == "US") 
            return statesOfUS.DefaultView; 
        else if (countryName == "Brazil") 
            return statesOfBrazil.DefaultView; 
 
        return null; 
    } 
 
    public DataTable GetStatesOfUS() 
    { 
        DataTable collection = new DataTable(); 
        collection.Columns.Add("State", typeof(string)); 
        collection.Rows.Add("Alaska"); 
        collection.Rows.Add("California"); 
        collection.Rows.Add("Colorado"); 
 
        return collection; 
    } 
 
    public DataTable GetStatesOfBrazil() 
    { 
        DataTable collection = new DataTable(); 
        collection.Columns.Add("State", typeof(string)); 
        collection.Rows.Add("Rio de Janeiro"); 
        collection.Rows.Add("Bahia"); 
        collection.Rows.Add("Roraima"); 
 
        return collection; 
    } 
} 
 
We have attached the sample for your reference and you can download the same from the following location. 
 
Please let us know if you would require further assistance. 
 
 
Regards, 
Jayaleshwari N 


Tim Larson
Replied On December 14, 2018 12:08 PM UTC

Thank you that is exactly what I needed.!

Tim

Jayaleshwari N [Syncfusion]
Replied On December 17, 2018 07:22 AM UTC

Hi Tim, 
 
Thanks for the update. Please get in touch if you would require further assistance. 
 
Regards, 
Jayaleshwari N 


CONFIRMATION

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

;