Dependency combo columns

Hello,

We got a following scenario:

One sfdatagrid got multiple columns. Two are dependency one of another one.

I need change a first column and generate a new datasource (on second column) with value select on the first.

 DgPartidas.Columns.Add(new GridComboBoxColumn() {
                MappingName = "IdActuacion",
                HeaderText = "Actuacion",
                ValueMember = "IdActuacion",
                DisplayMember = "Actuacion",
                DropDownStyle = DropDownStyle.DropDown,
                DataSource = actuaciones,
            });

            DgPartidas.Columns.Add(new GridComboBoxColumn()
            {
                MappingName = "IdFase",
                HeaderText = "Fase",
                ValueMember = "IdFase",
                DisplayMember = "Fase",
                DropDownStyle = DropDownStyle.DropDown,
                DataSource = fases,
            });

how can i do this??

Thanks   


1 Reply

SS Susmitha Sundar Syncfusion Team April 3, 2020 10:54 AM UTC

Hi Mel, 

Thank you for using Syncfusion controls. 

You can achieve your requirement by GridComboBoxColumn.DataSourceSelector property. Please refer to the below link, 

sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "Country", DataSource=countryInfo.Countries}); 
sfDataGrid1.Columns.Add(new GridComboBoxColumn() { MappingName = "ShipCity",IDataSourceSelector =new CustomSelector(), ValueMember = "ShipCityName", DisplayMember = "ShipCityName", }); 
 
 
public class CustomSelector : IDataSourceSelector 
{ 
    public IEnumerable GetDataSource(object record, object dataSource) 
    { 
        if (record == null) 
            return null; 
 
        var orderinfo = record as OrderInfo; 
        var countryName = orderinfo.Country; 
 
        var countryDetails = new CountryInfoRepositary(); 
 
        ////Returns ShipCity collection based on ShipCountry. 
        if (countryName == "Argentina") 
            return countryDetails.Argentina; 
        else 
            return countryDetails.Austria; 
    } 
} 


Change the GridComboBoxColumn datasource based on another GridTextColumn value:  https://github.com/syncfusion/winforms-demos/tree/master/DataGrid.WinForms/Samples/ComboBoxColumn 


Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 


Loader.
Up arrow icon