In the below attached Code Snippet, While trying to generate a gridview dynamically , I was not able to bind the values of Datable to to Combox Column.
I have tried populating combox items but when I select a Value its saving back to the Datatable.
Please help me out to bind the Datable Value to Combo box selected value and save the new item selected from the combox list back to the Datatable
this.ItemsGrid.ItemsSource = this.Datable1.DefaultView;
List<LOV> lovs = new List<LOV>();
lovs.Add(new LOV { Id= "1", Value = "test1" });
lovs.Add(new LOV { Id= "2", Value = "test2" });
lovs.Add(new LOV { Id= "3", Value = "test3" });
lovs.Add(new LOV { Id= "4", Value = "test4" });
lovs.Add(new LOV { Id= "5", Value = "test5" });
foreach ( Car cr in Cars)
{
switch (cr.CONTROL_TYPE.ToUpper())
{
case "COMBOBOX":
Telerik.Windows.Controls.GridViewComboBoxColumn comboBoxColumn = new Telerik.Windows.Controls.GridViewComboBoxColumn(); comboBoxColumn.DataMemberBinding = new Binding(cr.Name);
comboBoxColumn.ItemsSource = lovs;
comboBoxColumn.DisplayMemberPath = "Value";
comboBoxColumn.SelectedValueMemberPath = "Id";
comboBoxColumn.Header = cr.Name;
this.ItemsGrid.Columns.Add(comboBoxColumn);
break;
case "TEXTBOX":
Telerik.Windows.Controls.GridViewDataColumn txtBoxColumn = new Telerik.Windows.Controls.GridViewDataColumn();
txtBoxColumn.DataMemberBinding = new Binding(cr.Name);
txtBoxColumn.Header = cr.Name;
this.ItemsGrid.Columns.Add(txtBoxColumn);
break;
case "CHECKBOX":
Telerik.Windows.Controls.GridViewCheckBoxColumn chkBoxColumn = new Telerik.Windows.Controls.GridViewCheckBoxColumn();
chkBoxColumn.DataMemberBinding = new Binding(cr.Name);
chkBoxColumn.Header = cr.Name;
this.ItemsGrid.Columns.Add(chkBoxColumn);
break;
}
}
public class LOV
{
public string Id {get;set;}
public string Value{get;set;}
}