Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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/4/wpf/12.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# 将WPF数据网格复制到另一个不带列的数据网格中_C#_Wpf_Datagrid_Copy - Fatal编程技术网

C# 将WPF数据网格复制到另一个不带列的数据网格中

C# 将WPF数据网格复制到另一个不带列的数据网格中,c#,wpf,datagrid,copy,C#,Wpf,Datagrid,Copy,我需要复制一个DataGrid来删除最后一列。我尝试使用此代码,它正确设置了ItemSource,但列为空(在某些情况下,我绑定了object.property): 有人能帮我解决这个问题吗?提前谢谢。我认为您的问题是,在将网格添加到逻辑树之前,您正在设置ItemsSource属性 尝试将网格添加到其新父级,然后设置ItemsSource。列是否存在(并且没有数据),或者新网格是否看起来没有列?它存在,它有3行(正确),但空了。对不起,我没有得到我必须做的事情。你能再给我解释一下吗? DataG

我需要复制一个
DataGrid
来删除最后一列。我尝试使用此代码,它正确设置了
ItemSource
,但列为空(在某些情况下,我绑定了object.property):


有人能帮我解决这个问题吗?提前谢谢。

我认为您的问题是,在将网格添加到逻辑树之前,您正在设置ItemsSource属性


尝试将网格添加到其新父级,然后设置ItemsSource。

列是否存在(并且没有数据),或者新网格是否看起来没有列?它存在,它有3行(正确),但空了。对不起,我没有得到我必须做的事情。你能再给我解释一下吗?
DataGrid dg = new DataGrid();

foreach (DataGridColumn dgColumns in source.Columns.Where(i => i.Header != "Sending Result"))
{
    dg.Columns.Add(new DataGridTextColumn
    {
        Width = dgColumns.Width,
        Header = dgColumns.Header,
        Binding = new Binding(string.Format("{0}", dgColumns.SortMemberPath)));
    }
}

dg.ItemsSource = source.ItemsSource;