Я использую datagrid в WPF, данные привязаны успешно, но мне нужно добавить кнопку в конец строки. Например, если статус = 1, то добавить кнопку с красным цветом и содержанием, как «Не подтверждено», и если статус = 1, то добавить кнопку с синим цветом и содержанием, как «Смотрите подробности»Как добавить кнопку в конец строки программно
Обновлено:
if(status == "1")
{
//add a button to the end of row with red color and content
foreach (DataTable dt in result.Tables)
{
tb.Columns.Add("ButtonColumn", typeof(Button));
foreach (DataRow row in tb.Rows)
{
r["ButtonColumn"] = new Button
{
Name = "rowButton",
Content = "Row Button Content",
Width = 100,
Height = 30
};
}
}
stock_details.ItemsSource = new DataView(result.Tables["STOCK_OFFICER"]);
}else if(status != "1")
{
//add a button to the end of row with blue color and content
tb.Columns.Add("ButtonColumn", typeof(Button));
foreach (DataTable dtb in result.Tables)
{
foreach (DataRow ro in tb.Rows)
{
r["ButtonColumn"] = new Button
{
Name = "rowButton",
Content = "Second Button",
Width = 100,
Height = 30
};
}
}
stock_details.ItemsSource = new DataView(result.Tables["STOCK_OFFICER"]);
}
как я могу это сделать с использованием текущего кода?
Как добавить это 'dt.Columns.Add (" ButtonColumn ", typeof (Button));' в текущую таблицу данных? ca – Saif
Это может быть 'tb.Columns.Add (« ButtonColumn », typeof (Button));' – ViVi
Я обновил свой код, но он не добавил никаких кнопок! посмотрите обновленный код вопроса – Saif