Hello,
I coded in xaml.cs my datagrid with a single column of checkbox and button using factory and stackpanel. Right now I want to detect what column and row they are and if the checkbox ischecked = true. My column headers on datagrid are dynamic based on the dates range they chose
This is my sample code:
int extra = 1;
while (startDate < endDate.AddDays(1))
{
string combo1 = "combo" + extra;
var col2 = new DataGridTemplateColumn();
string colname = startDate.ToShortDateString() + " [" + Utils.ToDateTime(startDate).ToString("ddd") + "]";
col2.Header = colname;
var template2 = new DataTemplate();
var sp = new FrameworkElementFactory(typeof(StackPanel));
sp.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
var buttonfactoy = new FrameworkElementFactory(typeof(Button));
col2.CellTemplate = template2;
dgDaily.Columns.Add(col2);
dtDailyShift.Columns.Add(startDate.ToShortDateString(), typeof(string));
buttonfactoy.SetValue(Button.HeightProperty, 35.0);
buttonfactoy.SetValue(Button.ContentProperty, "CLICK FOR SHIFT");
buttonfactoy.SetValue(Button.MarginProperty, new Thickness(5));
buttonfactoy.SetResourceReference(Button.StyleProperty, "ButtonPrimary");
buttonfactoy.SetResourceReference(Button.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
// A column named 'System.Windows.Controls.DataGridTemplateColumn' already belongs to this DataTable.'
buttonfactoy.AddHandler(Button.ClickEvent, new RoutedEventHandler((o, f) => HandleColumnButtonClick(o, f)));
sp.AppendChild(buttonfactoy);
template2.VisualTree = sp;
extra++;
startDate = startDate.AddDays(1);
}
}