0
votes

This is my first WPF application so please bear with me! I have a datagrid that gets populated by binding a datatable to it. I then add a DataGridTemplateColumn which has a checkbox in it. On a button click event, I would like to copy all the rows from the datagrid with their checkboxes selected into a datatable. The reason for this is I have to perform various filtering and count functions on the data before writing to my database.

Thanks in advance!

2
Add a Boolean property to the bound data. Bind it to a checkbox. On button click pull out rows where bool is true. - Crowcoder
Thanks for the advice Crowcoder! I'm so new at this that I have trouble looping through the rows in the datagrid. Most of the examples I found on Google use the .Rows property, which I can't find. So at this stage even the simplest thing like looping is something that I have not yet figured out. - BabyDoll
Don't loop through the grid, loop through (or Linq through) the data that is bound to it. - Crowcoder

2 Answers

0
votes

Add a column with a checkbox to your gridview so you can check if the box is checked/unchecked.

Something like this:

foreach (GridViewRow gvr in YourGridView.Rows)
{
   if (CB.Checked == true) //CB = defined Checkbox
   {
    //save to database
   }
}
0
votes

Golden shovel candidate answer - the same problem has just arose in this question: DataGridCheckBoxColumn - How to return checked rows? Only instead of printing to console the required action should happen.