动态绑定到数据网格时出现问题
好吧,我有一个奇怪的小问题,我希望有人可以帮助我。
为了设置场景,我首先有一个对象:
public class Date
{
public DateTime _WeekDate;
public ICollectionView _WeekData;
}
我有一个组合框,它显示日期对象的列表。
<ComboBox Name="cbPickupDate" ItemsSource="{Binding Path=PickupDates}" DisplayMemberPath="WeekDate" />
好的,现在我采用所选日期对象的集合来为我的数据网格提供项目源:
<my:DataGrid ItemsSource="{Binding ElementName=cbPickupDate, Path=SelectedItem.WeekData}">
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding Path=ReqID}" Header="Request ID" />
<my:DataGridTextColumn Binding="{Binding Path=LineID}" Header="Line ID" />
<my:DataGridTextColumn Binding="{Binding Path=OrderID}" Header="Order ID" />
</my:DataGrid.Columns>
</my:DataGrid>
这一切都非常好,当我从组合框中选择不同的选项时,数据网格会更改其项目源。
但是,数据网格会在我指定的值之上为 WeekData 项中的每个值添加一个额外的列。因此,使用我展示的示例,它将显示 3 列 reqID、lineID 和 OrderID,以及另外 3 列完全相同的内容,因此总共 6 列。
感谢任何帮助,我真的对这个问题摸不着头脑。
提前致谢, 苏姆盖伊。
OK I have a weird little issue I hope someone can help me with.
To set the scene, I first of all have an object:
public class Date
{
public DateTime _WeekDate;
public ICollectionView _WeekData;
}
I have a combobox which displays a list of the Date objects.
<ComboBox Name="cbPickupDate" ItemsSource="{Binding Path=PickupDates}" DisplayMemberPath="WeekDate" />
OK, now I take the selected date object's collection to provide an itemssource for my datagrid:
<my:DataGrid ItemsSource="{Binding ElementName=cbPickupDate, Path=SelectedItem.WeekData}">
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding Path=ReqID}" Header="Request ID" />
<my:DataGridTextColumn Binding="{Binding Path=LineID}" Header="Line ID" />
<my:DataGridTextColumn Binding="{Binding Path=OrderID}" Header="Order ID" />
</my:DataGrid.Columns>
</my:DataGrid>
This all works very nicely, as I choose different options from the combobox the datagrid changes it's itemssource.
However, the datagrid adds an extra column for each value within my WeekData item on top of the ones I have specified. So using the example I've shown it would display 3 columns of reqID, lineID and OrderID and 3 more columns of exactly the same thing, so 6 in total.
Any help is appreciated, I'm really scratching my head over this one.
Thanks in advance,
SumGuy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关闭
AutoGenerateColumns
Turn off
AutoGenerateColumns
您是否尝试设置属性 AutoGenerateColumns< /a> 你的 DataGrid 为 false?我认为这会解决你的问题。
Have you tried to set the property AutoGenerateColumns of your DataGrid to false? I think that will solve your problem.