1

I am new to mvvm and I am not really familiar with the control DataGrid. I would like to known if we can do multiple binding on a DataGrid or anything.

Let me explain, I have 3 TextBox ( ProductName, Quantity, Price ) and i have 4 colums in my dataGrid ( ProductName, Quantity, Price, Total(price*quantity)). I also have 2 bouton, (add product) which will add the textBox value to the DataGrid and a bouton (save) which will save the content of the dataGrid in a DataBase.

How should I proceed ?

seb
  • 313
  • 1
  • 7
  • 19
  • 2
    I have no idea what you're talking about. Post the relevant code and XAML and please be specific about what issues / errors you're facing. – Federico Berasategui Oct 15 '13 at 18:47
  • 1
    You may be interested in reading an article I wrote for WPF beginners: [What is this "DataContext" you speak of?](http://rachel53461.wordpress.com/2012/07/14/what-is-this-datacontext-you-speak-of/). It will hopefully give you a better idea about how WPF works, and of what you need to build to get what you want. You may also want to check out [a simple MVVM example](http://rachel53461.wordpress.com/2011/05/08/simplemvvmexample/) :) – Rachel Oct 15 '13 at 19:03
  • The answer is 'yes, you can do that'. If such were not possible, wpf wouldn't be much use would it? Start with a tutorial and you'll see how it's done. – Gayot Fow Oct 15 '13 at 19:16

1 Answers1

2

The DataSource of the DataGrid should point to a collection of items.

Each row will be a single entity of your collection and it's properties can then be bound to a column (using templates).

See: Datagrid binding in WPF

Community
  • 1
  • 1
Vincent
  • 22,366
  • 18
  • 58
  • 61