TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Akos
NA
1
3.3k
Data Binding
Nov 30 2011 2:42 AM
Hi!
I have a problem with databinding. I made 2 datagrid. The 1st is a general WPF dagrid the 2nd is dxgrid control.
Both show the datas through entity framework.
I wanted to bind a current row to a texbox. If I click the row in a 1st table is working well and the data is showing in the textbox, but in the 2nd grid control not working.
What cause the problem?
This is the XAML code:
<Window x:Class="Valinor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="685" Width="895" Loaded="Window_Loaded" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:Valinor" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<Window.Resources>
<CollectionViewSource x:Key="itemsViewSource" d:DesignSource="{d:DesignInstance my:items, CreateList=True}" />
</Window.Resources>
<StackPanel>
<DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="200" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" Name="itemsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" Width="400">
<DataGrid.Columns>
<DataGridTextColumn x:Name="item_nameColumn" Binding="{Binding Path=item_name}" Header="item name" Width="SizeToHeader" />
</DataGrid.Columns>
</DataGrid>
<dxg:GridControl Name="grid" Height="232" Width="398" ItemsSource="{Binding Source={StaticResource itemsViewSource}}" AutoPopulateColumns="True">
<dxg:GridControl.View>
<dxg:TableView />
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn Name="col1" DisplayMemberBinding="{Binding Path=item_name}" Header="name" />
</dxg:GridControl.Columns>
</dxg:GridControl>
<Grid DataContext="{StaticResource itemsViewSource}" HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="item name:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="item_nameTextBox" Text="{Binding Path=item_name, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Center" Width="120" />
</Grid>
</StackPanel>
</Window>
This is a c# code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Valinor.ValinorEntities valinorEntities = new Valinor.ValinorEntities();
System.Windows.Data.CollectionViewSource itemsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("itemsViewSource")));
System.Data.Objects.ObjectQuery<Valinor.items> itemsQuery = this.GetitemsQuery(valinorEntities);
itemsViewSource.Source = itemsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
}
private System.Data.Objects.ObjectQuery<items> GetitemsQuery(ValinorEntities valinorEntities)
{
System.Data.Objects.ObjectQuery<Valinor.items> itemsQuery = valinorEntities.items;
return itemsQuery;
}
}
Reply
Answers (
1
)
Attendance System
CommandParameter Binding