0
votes

I need to convert WinForms framework dataGridView.rows and row.Cells to dataGrid in WPF.

I have already changed the code dataGridView1.DataSource = dt; to dataGrid1.ItemsSource = dt.DefaultView for WPF and then added the dataGrid Itemsource="{Binding}" on the WPF xaml form design. The dataGrid1 displays data.

What I'm stuck at is the parameterized query insert needs these dataGrid rows(items) so I can get at the row cells?

Solved it myself :)

1
Stop writing winforms style code-behind, take a couple of minutes to look at examples of MVVM and how it works with WPF. It will make your life easier in the long run.Kevin Cook
The way this sort of thing is done in wpf is to bind itemssource and work with the bound data. You're then working with a type safe collection and you have a named typed public property rather than cell x of row y. The resulting code is way less brittle, far easier to understand and maintain. Rather than bind to the view of a datatable or whatever, it is usual to define a row viewmodel and bind to an observablecollection of these. Otherwise, what is the point in using wpf? You gain nothing from the work you're doing and you might as well just leave it as winforms.Andy
Ok so I see this datagrid is now object based. So I need to create a model class of users with observable collection of getter setters and then define the datagrid columns as binding to each property name?ChrisR
solved it, so turns out if I used EF6 and bound the table correctly assigning each datatype to match what is bound from the table it worked.ChrisR

1 Answers

0
votes

solved it, so turns out if I used EF6 and bound the table correctly assigning each datatype to match what is bound from the table it worked. You can also use SpreadsheetLight, this is way faster than interop.