datagrid combobox column

aaa

New member
Joined
Mar 29, 2021
Messages
2
Programming Experience
Beginner
I have two questions:
1- how can I insert the value of selected datagrid combobox column in database?
2- how can I store the value of selected datagrid combobox column in a string?
 
To answer your first question, you shouldn't be inserting the value. You should simply be updating the row in the database you would have when the row has been edited. When you update the row, the the selected value in the data grid should be saved into the database assuming you have setup your binding correctly.

As for your second question, you would simply get the value of the cell as a string.
 
For the first question, i am getting the values of datagridcomboboxcolumn from another table. So that is way I am inserting it.
Second question, can you explain more
 
It doesn't matter if the data is coming from 1 table to 2 tables. If you are using WPF properly, including using the MVVM pattern for which WPF was designed against, the data grid is talking to to one View Model anyway. The job of the View Model is to adapt the Model to the needs of the View. So the Model may have two tables underlying it, but as far as the View (the data grid in this case) is concerned, it is just talking to a single table.

Now if you were not using WPF with MVVM, but trying to use WPF as if it were WinForms, then you are doing things wrong. You fill find yourself in a situation like this where you are trying to solve a data storage problem inside your view layer instead of your data layer.

As for getting the string, every data grid cell let's you ask for it contents. You can then simply convert that to a string if it is a simple type, or plumb through it, if it is a complex type.

But again, you are doing things wrong if you are trying to pull the value from the data grid directly. If you are using MVVM correctly, you should be pulling the value from your Model or View Model, not the View. The View is just meant to reflect the underlying View Model. You should not use the View as your source of truth.
 
Back
Top Bottom