I have a WinForms app, that displays a DataGridView. It is automatically populated from a BindingSource, and contains several rows of data. The columns include the standard things like strings. Some of these columns are CheckBoxes.
Name | User | Admin
---- ---- -----
John | X |
Fred | | X
I am writing some automated tests using TestStack.White. I can read the existing state of the CheckBoxes without issue.
How do I set or clear the checkboxes? I've tried:
Table.Rows[0].Cells[1].Value = true;
Fails because the underlying row/cell is deleted before White can read back the current value.
And also:
Table.Rows[0].Cells[1].SetValue(true);
Fails to set the new value.
Because your DataGridView
is bound to BindingSource
, you should change the Boolean value in BindingSource
rather than through the dataGridView
control.
Because TestStack.White
cannot access the underlying object model you will have to come up with a New button or Reset button. Or some GUI way (with logic) to clear the Checkbox values by setting the BindingSource's
boolean fields to false.
Here is some psuedo code to illustrate.
private void New_Click(object sender, System.EventArgs e)
{
DataTable dt = (DataTable)dgv.DataSource;
dt[1]["IsAdmin"].value = false;
//In ASP.Net you also need a dgv.Bind(); //this is not necessary in winforms
}
There should already be a way in your system to test with Checkboxes cleared, it should be consistent with how the end user currently do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With