Hi,
I have referred the sample( http://www.telerik.com/community/forums/wpf/gridview/can-t-use-celledittemplateselector-amp-celltemplateselector-together.aspx) for setting CellTemplate by using CellTemplateSelector.
I modified this sample to use DataTable as source instead of List<Item>(). In this case, i am not able to see any data in the second column of the Grid.
The code i have changed is:
public MainWindow()
{
InitializeComponent();
//List<Item> items = new List<Item>();
//items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(string), PropertyValue = "blabla" });
//items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(Visibility), PropertyValue = Visibility.Visible });
DataTable items = new DataTable();
items.Columns.Add("PropertyName");
items.Columns.Add("PropertyType",typeof(Type));
items.Columns.Add("PropertyValue");
DataRow row1 = items.NewRow();
row1[0] = "Property1";
row1[1] = typeof(string);
row1[2] = "blabla";
items.Rows.Add(row1);
row1 = items.NewRow();
row1[0] = "Property1";
row1[1] = typeof(Visibility);
row1[2] = Visibility.Visible;
items.Rows.Add(row1);
this.dataGrid1.ItemsSource = items;
}
class PropertyValueDataTemplateSelector:
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
var r= item as System.Data.DataRow;
Type value= r["PropertyType"] as Type;
if (value == typeof(string))
return this.TextTemplate;
else
return this.EnumTemplate;
}
Not able to figure out what is the issue.
Please give updated sample using DataTable as ItemSource.
Thanks for your help.
I have referred the sample( http://www.telerik.com/community/forums/wpf/gridview/can-t-use-celledittemplateselector-amp-celltemplateselector-together.aspx) for setting CellTemplate by using CellTemplateSelector.
I modified this sample to use DataTable as source instead of List<Item>(). In this case, i am not able to see any data in the second column of the Grid.
The code i have changed is:
public MainWindow()
{
InitializeComponent();
//List<Item> items = new List<Item>();
//items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(string), PropertyValue = "blabla" });
//items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(Visibility), PropertyValue = Visibility.Visible });
DataTable items = new DataTable();
items.Columns.Add("PropertyName");
items.Columns.Add("PropertyType",typeof(Type));
items.Columns.Add("PropertyValue");
DataRow row1 = items.NewRow();
row1[0] = "Property1";
row1[1] = typeof(string);
row1[2] = "blabla";
items.Rows.Add(row1);
row1 = items.NewRow();
row1[0] = "Property1";
row1[1] = typeof(Visibility);
row1[2] = Visibility.Visible;
items.Rows.Add(row1);
this.dataGrid1.ItemsSource = items;
}
class PropertyValueDataTemplateSelector:
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
var r= item as System.Data.DataRow;
Type value= r["PropertyType"] as Type;
if (value == typeof(string))
return this.TextTemplate;
else
return this.EnumTemplate;
}
Not able to figure out what is the issue.
Please give updated sample using DataTable as ItemSource.
Thanks for your help.