datagrid WPF中行的详细信息和标题 [英] Details and header of row in datagrid WPF
问题描述
各位大家好!
我试图在wpf中创建一个datagrid,其行详细信息是另一个datagrid。我已经做了。但现在我想处理它们。
详情:
+我想选择详细数据网格中的项目当我点击按钮时。我可以选择datagrid parent的项目。
+在 Rowheadtemplate 中添加togglebutton。当其中一个单元格的值是在线时,我想更改togglebutton的颜色backgoround
所以,我想问你。你能帮助我吗?
非常感谢你。 :)
我尝试过:
i catch select items of items datagrid parent:
Hello everybody!
I am trying to create a datagrid in wpf, which have row details is a other datagrid. I have done it. but now i want to process them.
Detail:
+ i want to select items in datagrid of detail when i click button. i could select items of datagrid parent.
+ In Rowheadtemplate i add togglebutton. I want to change color backgoround of togglebutton when value of one of the cell is "online"
So, i want to ask you. Can you help me?
Thank you so much. :)
What I have tried:
i catch select items of datagrid parent:
foreach (var item_dtg in dtg_ip.Items) // click icon-> row of dtg_IP
{
if (((TextBlock)dtg_ip.Columns[0].GetCellContent(item_dtg)).Text.Trim() == imageTag.name)
{
dtg_ip.SelectedItem = item_dtg;
dtg_ip.ScrollIntoView(item_dtg);
break;
}
}
推荐答案
我遇到了两个问题:
+在Rowheadtemplate中我添加了togglebutton。当其中一个单元格的值为在线时,我想更改togglebutton的颜色backgoround:
i have done a problem two:
+ In Rowheadtemplate i add togglebutton. I want to change color backgoround of togglebutton when value of one of the cell is "online":
private void Button_Click_2(object sender, RoutedEventArgs e)
{
for (int i = 0; i < dataGrid1.Items.Count; i++)
{ // Surat
DataGridRow row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(i);
FrameworkElement tb = GetTemplateChildByName(row, "RowHeaderToggleButton");
if (((TextBlock)dataGrid1.Columns[1].GetCellContent(dataGrid1.Items[i])).Text == "Online")
{
ToggleButton tgb = (ToggleButton)tb;
tgb.Background = Brushes.Blue;
}
}
}
剩下的第一个问题。你能给我一个解决方案吗?非常感谢你。
The first remaining issue.Can you have me a solution? thank you so much.
这篇关于datagrid WPF中行的详细信息和标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!