Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
141487 | Dec 13,2018 07:20 PM UTC | Dec 17,2018 07:22 AM UTC | WinForms | 3 |
![]() |
Tags: SfDataGrid |
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;
}
} |
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.
This page will automatically be redirected to the sign-in page in 10 seconds.