[英]WPF ADO.NET no results returned
I have a problem with returning results to DataGrid in WPF application using ADO.NET Framework. 我在使用ADO.NET Framework将结果返回到WPF应用程序中的DataGrid时遇到问题。
First record is text, second too, third is date(if anyone could give me an answer how to make this string would be great). 第一个记录是文本,第二个记录也是,第三个记录是日期(如果有人可以给我一个答案,那么如何制作此字符串会很棒)。
First, DataGrid XAML code 一,DataGrid XAML代码
<DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Grid.ColumnSpan="4" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource testViewSource1}}" Margin="113,290,0,0" Name="testDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="319" Loaded="testDataGrid_Loaded">
<DataGrid.Columns>
<DataGridTextColumn x:Name="numerZamowieniaColumn" Binding="{Binding Path=numerZamowienia}" Header="numer Zamowienia" Width="SizeToHeader" />
<DataGridTextColumn x:Name="iloscDostawcowColumn" Binding="{Binding Path=iloscDostawcow}" Header="ilosc Dostawcow" Width="SizeToHeader" />
<DataGridTemplateColumn x:Name="dataUtworzeniaColumn" Header="data Utworzenia" Width="SizeToHeader">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Path=dataUtworzenia, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I made event handler when this DataGrid is loaded : 加载此DataGrid时,我制作了事件处理程序:
zamowienieEntities zam = new zamowienieEntities();
private void testDataGrid_Loaded(object sender, RoutedEventArgs e)
{
IBindingList users = ((from d in zam.Test
select new { d.numerZamowienia, d.iloscDostawcow, d.dataUtworzenia }
) as IListSource).GetList() as IBindingList;
this.testDataGrid.DataContext = users;
}
This is one of many approaches trying to make this work, and I'm sityting at it for couple hours now, and can't really find any specific answers. 这是尝试完成这项工作的许多方法之一,我现在要花几个小时来讨论它,并且真的找不到任何具体答案。
Thanks in advance. 提前致谢。
When you do this 当你这样做
ItemsSource="{Binding Source={StaticResource testViewSource1}}"
you bind ItemsSource
to some testViewSource1
resource so changing DataContext
, as you do in this line 您将
ItemsSource
绑定到某些testViewSource1
资源,因此更改了DataContext
,就像您在此行中所做的那样
this.testDataGrid.DataContext = users;
won't affect source of DataGrid
items. 不会影响
DataGrid
项的来源。 One solution to your problem is to set ItemsSource
directly instead of DataContext
解决您的问题的一种方法是直接设置
ItemsSource
而不是DataContext
this.testDataGrid.ItemsSource = users;
and then you don't need ItemsSource
binding, or if you want to set DataContext
then you need to change ItemsSource
binding to 然后就不需要
ItemsSource
绑定,或者如果要设置DataContext
则需要将ItemsSource
绑定更改为
ItemsSource="{Binding}"
which will bind ItemSource
to current DataContext
它将
ItemSource
绑定到当前的DataContext
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.