Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选中DataGrid中的复选框应选中RowDetails中的所有复选框_C#_Wpf_Datagrid - Fatal编程技术网

C# 选中DataGrid中的复选框应选中RowDetails中的所有复选框

C# 选中DataGrid中的复选框应选中RowDetails中的所有复选框,c#,wpf,datagrid,C#,Wpf,Datagrid,我有一个DataGrid发货和产品。装运始终显示,并且每次装运的产品都显示在一行详细信息中,当我双击一行时,该行将可见 在DataGrid中,我使用了一个自定义复选框列: <DataGridTemplateColumn> <DataGridTemplateColumn.Header> Copy </DataGridTemplateColumn.Header> <DataGridTemplateColumn.CellTemp

我有一个DataGrid发货和产品。装运始终显示,并且每次装运的产品都显示在一行详细信息中,当我双击一行时,该行将可见

在DataGrid中,我使用了一个自定义复选框列:

<DataGridTemplateColumn>
   <DataGridTemplateColumn.Header>
       Copy
   </DataGridTemplateColumn.Header>
   <DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
           <CheckBox IsChecked="{Binding Path=DoCopy, Mode=TwoWay, 
             UpdateSourceTrigger=PropertyChanged}"
       </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
问题:

当我单击DataGrid中的复选框时,所有产品的复选框都被选中。但仅当未显示行详细信息时。如果显示了RowDetails,并且我单击了“main”复选框,则会选中它,但“details”复选框不会

此外,如果我以前打开和关闭了一行详细信息,然后选中“main”复选框,也会发生同样的情况。产品的复选框保持未选中状态

装运有一个
列表
,其中包含该装运的所有产品

有什么想法吗?

thakrage, 处理此问题的最简单方法是,对每个“复制”复选框行使用click event,在该事件中,您可以设置Docopy=true或您想做的任何事情

然后在datagrid外部定义一个复选框,然后设置边距,使复选框与数据头完全相同,并弹出一个单击事件来检查所有行

请参阅下面的示例代码:

<CheckBox Name="chkbox_chkall" Click="chkbox_chkall_Click" Content="Check all" BorderBrush="#FF828282" Foreground="#FF5B585A"/>
我明白了,伙计们。 我好像忘了实现
INotifyPropertyChanged

现在一切正常。谢谢:-)

以下代码适合我。我只想在某个事件上选中datagrid的所有复选框。下面的代码只是选中了datagrid中的所有复选框。在我的例子中,列0是一个复选框列

private void SelectAll()
    {
        for (int i = 0; i < dgVehicle.Items.Count; i++)
        {
            DataGridRow row = (DataGridRow)dgVehicle.ItemContainerGenerator.ContainerFromIndex(i);

            if (row != null)
            {
                CheckBox chk = dgVehicle.Columns[0].GetCellContent(row) as CheckBox;
                chk.IsChecked = true;
            }
        }
    } 
private void SelectAll()
{
对于(int i=0;i
也许这可以帮助您。
<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
       <CheckBox IsChecked="{Binding Path=DoCopy, Mode=TwoWay, 
         UpdateSourceTrigger=PropertyChanged}" Click="chkBoxRow_Click"
   </DataTemplate>
    private void chkbox_chkall_Click(object sender, RoutedEventArgs e)
    {
        CheckBox chkbox_chkall = sender as CheckBox;
        foreach (OnlineActivatedProducts rowItem in (grdProducts.ItemsSource))
        {
            CheckBox chk = grdProducts.Columns[6].GetCellContent(rowItem) as CheckBox;
            if (chkbox_chkall.IsChecked == true)
            {
                chk.IsChecked = true;
            }
            else
            {
                chk.IsChecked = false;
            }
            chkBoxRow_Click(chk, e); // which bubbles each rows checked / unchecked event
        }
    } 

    private void chkBoxRow_Click(object sender, RoutedEventArgs e)
    {
        if (chkBoxContent.IsChecked.Value)
        {
            //if checked do something here 
        }
        else if (!chkBoxContent.IsChecked.Value)
        {
            //if unchecked do something here
        }
    }
private void SelectAll()
    {
        for (int i = 0; i < dgVehicle.Items.Count; i++)
        {
            DataGridRow row = (DataGridRow)dgVehicle.ItemContainerGenerator.ContainerFromIndex(i);

            if (row != null)
            {
                CheckBox chk = dgVehicle.Columns[0].GetCellContent(row) as CheckBox;
                chk.IsChecked = true;
            }
        }
    }