Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
150522 | Jan 9,2020 05:50 PM UTC | Feb 10,2020 01:31 PM UTC | WPF | 22 |
![]() |
Tags: GridControl |
private void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
this.DataGrid.AutoGenerateColumns = false;
this.DataGrid.ItemsSource = dt;
DataTemplate cellTemplate = new DataTemplate();
FrameworkElementFactory frameworkElement = new FrameworkElementFactory(typeof(ComboBox));
Binding displayBinding = new Binding() { Path = new PropertyPath("EmployeeID") };
frameworkElement.SetValue(ComboBox.ItemsSourceProperty, customerCollection);
frameworkElement.SetValue(ComboBox.DisplayMemberPathProperty, "ID");
frameworkElement.SetValue(ComboBox.SelectedValueProperty, displayBinding);
cellTemplate.VisualTree = frameworkElement;
this.DataGrid.Columns.Add(new GridTemplateColumn() { MappingName = "EmployeeID", CellTemplate = cellTemplate });
DataTemplate cellTemplate1 = new DataTemplate();
FrameworkElementFactory frameworkElement1 = new FrameworkElementFactory(typeof(ComboBox));
Binding displayBinding1 = new Binding() { Path = new PropertyPath("EmployeeName") };
frameworkElement1.SetValue(ComboBox.ItemsSourceProperty, customerCollection);
frameworkElement1.SetValue(ComboBox.DisplayMemberPathProperty, "Name");
frameworkElement.SetValue(ComboBox.SelectedValueProperty, displayBinding1);
cellTemplate1.VisualTree = frameworkElement1;
this.DataGrid.Columns.Add(new GridTemplateColumn() { MappingName = "EmployeeName", CellTemplate = cellTemplate1 });
this.DataGrid.Columns.Add(new GridTextColumn() { MappingName = "Destination" });
}
private void AddColumns_Click(object sender, RoutedEventArgs e)
{
dt.Columns.Add("EmployeeAge", typeof(int));
foreach (System.Data.DataRow row in dt.Rows)
{
row[3] = r.Next(25, 30);
}
this.DataGrid.Columns.Add(new GridTextColumn() { MappingName = "EmployeeAge" });
this.DataGrid.ItemsSource = dt;
} |
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.