Editing a cell in a listview using white

Oct 17, 2012 at 11:08 AM

I am using a listview and I want to edit a cell which has custom control- Checkbox, I need to edit it as a part of my test.

Can anybody please tell me how to get a cell from a listview and edit its content (in this case toggle the Checkbox) ?

Please, I am kind of stuck in here. Detail explanation will be appreciated.

Oct 17, 2012 at 1:08 PM
Edited Oct 17, 2012 at 1:12 PM

Hi

try the following if you have the row

use the following extension method

 

 

 /// <summary>
    /// Gets the cells.
    /// </summary>
    /// <param name="row">The row.</param>
    /// <returns></returns>
    public static ListViewCells GetCells(this ListViewRow row, ListViewHeader header)
    {

      AutomationElementCollection coll = row.AutomationElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell"));

      return new ListViewCells(new BricksCollection<AutomationElement>(coll), row.ActionListener, header);

    }

 

now you can use

 

 

Listview view = ..<get the listview>...

ListViewCells cells = view.Rows[1].GetCells(view.Header);

ListViewCell cell = cells[<name or index>];

 

 

now you can work with the cell.

 

Extend ListViewCell with a method which get Controls from the cell.

 

 

public static CheckBox GetCheckBox(this ListViewCell cell)

{
  //do action to get content from cell
}

 

then

 

 

CheckBox box = cell.GetCheckBox();

box.Click();

 

 

Throndorin

Oct 18, 2012 at 8:53 AM

Hey Throndorin, 

Thanks for your valuable and detailed suggestion. 

But here

 AutomationElementCollection coll = row.AutomationElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell"));

In this statement How can we use "DataGridCell" to get a listViewCell ? And Still if I use ListViewCell in that place, the "coll.Count" is zero. I tried a lot of options, still its zero.

Can you tell me what to do in here ?

Oct 18, 2012 at 11:32 AM

ControlType of ListView is DataGrid

 

Please use UIAVerify or UISpy to get all infotrmation from the ListViewCell you can also use Snoop