0

我设计了下面DataGrid并用三列映射。我已经把这些记录拿走了Linq并分配了这个Grid。但是这个网格显示了几次记录。不知道是什么行为?如何解决这个问题?

<DataGrid Name="workgrid" ItemsSource="{Binding it}" Margin="12,152,0,148" HorizontalAlignment="Left" Width="517">
        <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Width="100" Binding="{Binding PersonName}" />
        <DataGridTextColumn Header="Place" Width="100" Binding="{Binding Place}" />
        <DataGridTextColumn Header="Amount" Width="100" Binding="{Binding Amount}" />
        </DataGrid.Columns>
    </DataGrid>


var objResult = from c in objEntities.PersonAccounts
        select new { c.PersonName, c.Amount, c.Place };

workgrid.ItemsSource = objResult;  

Anu 的帮助或建议将不胜感激!!!

4

1 回答 1

0

将 AutoGenerateColumns 设置为 false :

<DataGrid AutoGenerateColumns="False" Name="workgrid" ItemsSource="{Binding it}" Margin="12,152,0,148" HorizontalAlignment="Left" Width="517">
    <DataGrid.Columns>
    <DataGridTextColumn Header="Name" Width="100" Binding="{Binding PersonName}" />
    <DataGridTextColumn Header="Place" Width="100" Binding="{Binding Place}" />
    <DataGridTextColumn Header="Amount" Width="100" Binding="{Binding Amount}" />
    </DataGrid.Columns>
</DataGrid>

此外,您不需要显式设置 ItemsSource 并通过绑定。只用一个。

于 2013-03-27T11:04:41.260 回答