private void gridView_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyName == "code" && rdbCode.IsChecked == true)
{
e.Column.Header = "Acct Code";
}
else if (e.PropertyName == "code" && rdbPart.IsChecked == true)
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "um")
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "part" && rdbPart.IsChecked == true)
{
e.Column.Header = "Part ID";
}
else if (e.PropertyName == "part" && rdbCode.IsChecked == true)
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "check")
{
CheckBox chk = new CheckBox();
e.Column.Header = chk;
chk.Content = "Update All";
}
}
我有一个Datagrid,在列标题中有一个动态创建的复选框。如何将此复选框链接到已选中和未选中的事件,以便我可以选中或取消选中标题下方的整个列。
答案 0 :(得分:0)
private void gridView_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyName == "code" && rdbCode.IsChecked == true)
{
e.Column.Header = "Acct Code";
}
else if (e.PropertyName == "code" && rdbPart.IsChecked == true)
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "um")
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "part" && rdbPart.IsChecked == true)
{
e.Column.Header = "Part ID";
}
else if (e.PropertyName == "part" && rdbCode.IsChecked == true)
{
e.Column.MaxWidth = 0;
}
if (e.PropertyName == "check")
{
CheckBox chk = new CheckBox();
e.Column.Header = chk;
chk.Content = "Update All";
chk.Checked += chk_Checked;
chk.Unchecked += chk_Unchecked;
}
}
这很有效。