gpt4 book ai didi

c# - WPF Datagrid 显示列两次

转载 作者:行者123 更新时间:2023-12-03 22:56:12 25 4
gpt4 key购买 nike

我已经通过将数据绑定(bind)到数据库列成功地在数据网格中显示数据,但问题是,所有数据列在完全显示后出现两次,即(id,user_id,status,id,user_id,status,)。如何摆脱这个,这是我的代码

<DataGrid x:Name="Grid_display" Grid.ColumnSpan="3" Margin="63,51,36,10" Grid.RowSpan="2">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Path=id}"/>
<DataGridTextColumn Header="Publisher ID" Binding="{Binding Path=user_id}"/>
<DataGridTextColumn Header="Publication Title" Binding="{Binding Path=title}"/>
<DataGridTextColumn Header="Published Date of Document" Binding="{Binding Path=published_date}"/>
<DataGridTextColumn Header="File" Binding="{Binding Path=file}"/>
<DataGridTextColumn Header="Status" Binding="{Binding Path=status}"/>

</DataGrid.Columns>
</DataGrid>

private void display_btn_Click(object sender, RoutedEventArgs e)
{
List<publication> q = (from p in db.publications where p.user_id == get_id select p).ToList();
Grid_display.ItemsSource = q;

}

最佳答案

您必须设置 AutoGenerateColumns="False"在您的数据网格上。默认情况下它是 true 并且正在添加另一组列。

<DataGrid x:Name="Grid_display" Grid.ColumnSpan="3" AutoGenerateColumns="False" 
Margin="63,51,36,10" Grid.RowSpan="2"/>

关于c# - WPF Datagrid 显示列两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24155579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com