Unable to set the value in a cell

Oct 19, 2010 at 7:38 PM

I am trying to enter the value and read the value (to verify) from a cell. The hierarchy in UI spy is

---list view records
------ list view
-------datagrid
--------- header ("hearder information")
---------dataitem
 ----------cell

This is the code i have used
 ListView listView = Window.Get<ListView>(SearchCriteria.ByControlType(ControlType.DataGrid));
          
            ListViewRows Rows = listView.Rows;
            MessageBox.Show(Rows.Count.ToString());
             listView.Rows[5].Select();
             Rows[5].Cells["Column Header"].DoubleClick();
            
Also, tried this
        ListViewCell cell = Rows[1].Cells["Column Header"];
             cell.DoubleClick();

And this
             listView.Rows[5].Select();
              listView.Rows[5].Cells[1].Enter("ABC");

   None of these seem to be working. Can someone please help? It is a Wpf app.

Oct 20, 2010 at 7:05 AM

Hi

you need to enable the cell edit mode to enter text in the cell, so the last try can only work if one of the first steps work.

 

 

ListViewCell cell = Rows[1].Cells["Column Header"];
cell.DoubleClick();

 

 

is cell not null?

 

try

 

 

cell.Click();
Thread.Sleep(100);
cell.Click();

 

 

set a break point after that

 

is the cell in edit mode?

 

Throndorin

 

Oct 20, 2010 at 1:16 PM
Edited Oct 20, 2010 at 1:43 PM

Thanks Throndorin. The cell is in edit mode. I can manually enter the value by double clicking. ALso, I had tried to use the CLickable point to enter the value and it works well however, i am not able to enter the value using cell [index], i am afraid the clickable point is probably not the good approach. Is there a way to set the cell in edit mode, how else i can verify that? thanks.

Oct 20, 2010 at 1:46 PM

Hi

 

try

 

Keyboard.Instance.Enter( "my text");

 

Throndorin

Oct 20, 2010 at 1:54 PM
Edited Oct 21, 2010 at 1:48 AM

Thanks, How about the cell location?  how do i click on a particular cell( row2, column1).  I know the KeyboardInstance did work for me after i use clickable point to tell the location to enter the text. I am not sure why i can't perform any action on the cell.  i can click on column, i can also select a particular row. Then why does it show an error message," object reference not set to an instance of object" when trying to click on cell?

ListViewRow

 

first = listView.Rows[2];

first.Select();

// second row

 

Thread

.Sleep(500);

ListViewColumns

columns = listView.Header.Columns;

columns[9].Click();

 

Thread

.Sleep(500);

 

 

ListViewCell cell = Rows[3].Cells["columnheader2"

];

cell.DoubleClick();

Oct 21, 2010 at 7:25 AM

 

your cell seems to be null :(

 

is Rows[3].Cells instanciated or is the count of the list 0?

if so try this:

ListView view = window.Get<ListView>(SearchCriteria.ByAutomationID("listViewID"));

ListViewRow row = view.Rows[3];

PropertyCondition propertyClassName = new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell");
PropertyCondition propertyConditionControlType = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom);
//the count of cells cannot be correct performed, if many cells are displayed
AutomationElementCollection itemCollection = row.AutomationElement.FindAll(TreeScope.Children, new AndCondition( propertyClassName, propertyConditionControlType));
								 
ListViewCells cells = new ListViewCells( itemCollection, view.ActionListener, view.Header );

 

is cells not empty?

 

if so the cells might be custom controls and you need an other way.

Throndorin

Oct 21, 2010 at 12:39 PM

Thanks Throndorin. Yes, the cell is null and the cell count is also zero. would u please give some details for the above  code u provided? I am sorry for taking ur time but i do not really know how to work with this . your help is appreciated. Thx.

Oct 21, 2010 at 1:24 PM
Edited Oct 21, 2010 at 1:25 PM

Have you tried this part i posted?

 

or is there a problem with the code above?

Oct 21, 2010 at 1:55 PM
Edited Oct 22, 2010 at 1:43 AM

yes, I have tried the following code

ListView view = window.Get<ListView>(SearchCriteria.ByAutomationID("listViewID")); ==== There is not automation id assigned for DataGrid i have therefore, iam using ControlType.DataGrid, is this correct? 
ListViewRow row = view.Rows[3];

PropertyCondition propertyClassName = new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell");
PropertyCondition propertyConditionControlType = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom);
//the count of cells cannot be correct performed, if many cells are displayed
AutomationElementCollection itemCollection = row.AutomationElement.FindAll(TreeScope.Children, new AndCondition( propertyClassName, propertyConditionControlType));
								 
ListViewCells cells = new ListViewCells( itemCollection, view.ActionListener, view.Header ); get the below error

I get the error message for this line of code : ListViewCells cells = new ListViewCells( itemCollection, view.ActionListener, view.Header ); - cannot convert from system.windows.automation.automation element to System.Collection.GenericList.

Also, i noticed that in UI spy for the cell object , the Control Type property is listed as Control.Custom  ==  does it mean it is a custom object?

Thanks.

Oct 22, 2010 at 8:15 AM

Hi

yes this is much more complicated.

ok than you should have a class MyListViewCell, which hold the cells from the row

 

I will send you some code snippets we use to handle this.

 

Throndorin

Oct 22, 2010 at 1:21 PM

Thanks Throndorin. I really appreciate you help on this.

Oct 24, 2010 at 3:43 AM

Throndorin,

Can you please provide the code snippets that can be used to handle this? Thanks in advance,

Oct 24, 2010 at 7:47 AM

I have send a mail.

first I answer to your mail, (comes back to me) and second to the mail you posted in the other thread (Does not come back)

 

Throndorin

Oct 25, 2010 at 1:17 PM

Throndorin,

I did  not receive any email from you. My email address is sonia_20026@yahoo.com sonia (underscore)20026 @ yahoo. Can you please resend it when you have a chance? Thanks for yuor time.

Oct 25, 2010 at 2:06 PM

send again

Oct 25, 2010 at 2:41 PM

I got the email. Will let you know the results. Thanks.

Nov 26, 2010 at 9:02 AM

Hi,

For Custom Data Grid control I am getting the same error

Error 2 Argument 1: cannot convert from 'System.Windows.Automation.AutomationElementCollection' to 'System.Collections.Generic.List<System.Windows.Automation.AutomationElement>' C:\Documents and Settings\kavin\My Documents\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs 137 53 ConsoleApplication2

Please let me know the codesnippets that can be used to handle this as provided to sonia

My email-id is kavin@tek.com

Thanks, Kavitha