2

I just would like to make a simple dataBinding between a textbox field and a dataGridView control.. How can I make this? enter image description here

With Winforms I would add a Databinding with this

 NameTextBox.DataBindings.Add("Text", ds, "Categories.Category_Product.ProductName"); 

But I'm trying to do this in wpf and I don't see how to make this..

Here's the code for the page.

 public partial class Categories : Window { public Categories() { InitializeComponent(); DataTable dt = CATEGORIE_MANAGER.GetList(false); listViewListe.ItemsSource = dt.DefaultView; cbbParent.ItemsSource = dt.DefaultView; } } 

How can I link the textBox with the ListViewListe? Should I use the dataContext? How can I do that?

Thanks

2 Answers 2

2
<TextBox x:Name="NameTextBox" DataContext="{Binding ElementName=listViewListe, Path=SelectedItem}" Text="{Binding ProductName}"/> 
Sign up to request clarification or add additional context in comments.

1 Comment

<TextBox x:Name="NameTextBox" DataContext="{Binding ElementName=listViewListe, Path=SelectedItem"} Text="{Binding Path=ProductName}"/> works Thanks a lot
1

In your Xaml

<TextBox Text={Binding ElementName=NameTextBox,Path=SelectedItem.ProductName} /> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.