0

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!

3
  • Add a Boolean property to the bound data. Bind it to a checkbox. On button click pull out rows where bool is true. Commented Jan 12, 2015 at 10:26
  • 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. Commented Jan 12, 2015 at 10:42
  • Don't loop through the grid, loop through (or Linq through) the data that is bound to it. Commented Jan 12, 2015 at 10:45

2 Answers 2

0

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
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your input Katz, unfortunately I'm using a DataGrid and there is no .Rows property. If I understand correctly you have to use the .Item property.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.