-
November 4th, 2009, 12:19 PM
#1
Databinding problem
Hi
I have a problem when binding data from datatable to a TexBox.
There's a ListBox connected to DataTable and a TextBox connected to one field from the same DataTable.
This binding in XAML works fine:
<TextBox Name="txtNazwa" Text="{Binding Path=NAZWA}" />
moving in a ListBox changes values ina TextBox. But when I'm trying to do binding in code below nothing happens in a TextBox.
// set "global" datacontext
grdKartoteka.DataContext = Kartoteka.klejeDataTable.DefaultView;
// set source for a list (same as datacontext but in case of lists
// ItemsSource has to be specified
listNazwyTowarow.ItemsSource = Kartoteka.klejeDataTable.DefaultView;
listNazwyTowarow.DisplayMemberPath = "NAZWA";
// binding for a textbox
Binding binding = new Binding();
binding.Source = Kartoteka.klejeDataTable.DefaultView;
binding.Path = new PropertyPath("NAZWA");
binding.Mode = BindingMode.TwoWay;
txtNazwa.SetBinding( TextBlock.TextProperty, binding);
What's wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|