I am building a database-access program that dynamically creates datagrid columns, as well as dynamically requests data based on account preferences. I have several datagrids that work in identical manners and for the most part they work perfectly. All of my text columns bind to the datatables that I use to store all of the data, however I cannot figure out how to get my template columns to bind to a datatable column. I am using the template columns as datepicker columns, if that helps at all.
The visuals load fine: i.e. The columns load perfectly in the sense that I can see and interact with them without an issue. The main problem is binding them to the datatables themselves. Any help is appreciated. Please remember that the datagrids always exist, it is only the columns that are completely dynamic.
Here is the basic version of what I have done (In wpf)
<ResourceDictionary>
<DataTemplate x:Key="datePickerTemplate">
<DatePicker Text="{Binding}"/>
</DataTemplate>
</ResourceDictionary>
<DataGrid x:Name="datagrid_1" ItemsSource = "{Binding}" AutoGenerateColumns = "False">
(In c#)
//creates a text column (works just fine)
DataGridTextColumn textcolumn = new DataGridTextColumn();
textcolumn.Header = "text column";
textcolumn.Binding = new Binding("bind test column"); //text columns bind fine
datagrid_1.Columns.Add(setexpmeetdatecolumn);
//create template column
DataGridTemplateColumn templatecolumn = new DataGridTemplateColumn();
templatecolumn.Header = "date template column";
templatecolumn.CellTemplate = (DataTemplate)FindResource("datePickerTemplate");
(problem -> ) templatecolumn.Binding = new Binding("bind test column"); //this is what I need to accomplish, but am not finding any legible answers that are coherent to understand.
datagrid_1.Columns.Add(templatecolumn);