How can I check or uncheck a datagridview using White

I have a WinForms application that displays a DataGridView. It is automatically populated from BindingSource and contains several rows of data. Columns include standard elements such as rows. Some of these columns are CheckBoxes.

Name | User | Admin ---- ---- ----- John | X |
Fred | | X

I am writing several automated tests using TestStack.White. I can read the existing state of CheckBoxes without any problems.

How to check or uncheck the boxes? I tried:

  • Table.Rows[0].Cells[1].Value = true;

Fails because the base row / cell is deleted before White returns the current value.

And:

  1. Table.Rows[0].Cells[1].SetValue(true);

Failed to set new value.

+5
source share
4 answers

Since your DataGridView bound to a BindingSource , you should change the boolean value in the BindingSource , not through the DataGridView control.

+1
source

Since TestStack.White cannot access the underlying object model, you will have to come up with a β€œCreate” button or a Reset button. Or some GUI way (with logic) to clear Checkbox values ​​by setting BindingSource's boolean fields to false.

Here is an example 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 } 

Your system should have a check method with cleared checkboxes; it should match how the end user does it.

+1
source

Is this my useful way to set values? DataGridView column window - value and functionality :

 foreach (DataGridViewRow row in dataGridView1.Rows) { row.Cells[CheckBoxColumn1.Name].Value = true; } 

Or what is Table for an object?

0
source

I believe that checkboxes in C # have the Checked property. And although it is in a DataGridView, I believe that the property of the controls remains the same.

So you can try this instead

 Table.Rows[0].Cells[1].Checked = true; 

Resources : http://www.c-sharpcorner.com/uploadfile/mahesh/checkbox-in-C-Sharp3/

0
source

Source: https://habr.com/ru/post/1241588/


All Articles