Hi
Im trying to change MS Datagrid to SfDataGrid in my application, but I have problem with setting ItemsSource for this control (in MS it worked).
I need to load data from database and set DataContext for entire Grid to synchronize with textboxes.
Is it possible in that way?
Output window when i run app says:
System.Windows.Data Error: 40 : BindingExpression path error: 'CustomersViewSource' property not found on 'object' ''DataRowView' (HashCode=11766267)'. BindingExpression:Path=CustomersViewSource; DataItem='BindingListCollectionView' (HashCode=20908074); target element is 'SfDataGrid' (Name='CustomerDataGrid'); target property is 'ItemsSource' (type 'Object')
Please help to understand what im doing wrong.
Here is my code:
Class MainWindow
Dim CustomersViewSource As System.Windows.Data.CollectionViewSource
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
Dim NORTHWNDDataSet As WpfApp1.NORTHWNDDataSet = CType(Me.FindResource("NORTHWNDDataSet"), WpfApp1.NORTHWNDDataSet)
Dim NORTHWNDDataSetCustomersTableAdapter As WpfApp1.NORTHWNDDataSetTableAdapters.CustomersTableAdapter = New WpfApp1.NORTHWNDDataSetTableAdapters.CustomersTableAdapter()
NORTHWNDDataSetCustomersTableAdapter.Fill(NORTHWNDDataSet.Customers)
CustomersViewSource = CType(Me.FindResource("CustomersViewSource"), System.Windows.Data.CollectionViewSource)
CustomersViewSource.View.MoveCurrentToFirst()
End Sub
End Class
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:Syncfusion="http://schemas.syncfusion.com/wpf" x:Class="MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:NORTHWNDDataSet x:Key="NORTHWNDDataSet"/>
<CollectionViewSource x:Key="CustomersViewSource" Source="{Binding Customers, Source={StaticResource NORTHWNDDataSet}}"/>
</Window.Resources>
<Grid x:Name="Grid1" DataContext="{StaticResource CustomersViewSource}">
<Label Content="Company Name:" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="CompanyNameTextBox" HorizontalAlignment="Left" Height="22" Margin="138,6,-132,4" Grid.Row="0" Text="{Binding CompanyName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Label Content="Contact Name:" HorizontalAlignment="Left" Margin="3" Grid.Row="1" VerticalAlignment="Center"/>
<TextBox x:Name="ContactNameTextBox" HorizontalAlignment="Left" Height="22" Margin="138,6,-132,4" Grid.Row="1" Text="{Binding ContactName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
<Syncfusion:SfDataGrid x:Name="CustomerDataGrid" Grid.Row="2" AutoGenerateColumns="True" ItemsSource="{Binding CustomersViewSource}" Grid.ColumnSpan="2" />
</Grid>
</Window>
Attachment:
WpfApp1_250dc5f9.zip