Listview

Sep 1, 2009 at 2:52 PM

I’m trying to work with a Datagrid in Silverlight without much success.  I’m trying to get the data from it, with the following methods, but nothing seems to work.  Can you help me out?

Datagrid (The first row is a Headerrow, the last column is blank.  The last column shows up in the UI, but not in the source code for the project or UISPY):

|| Name        || Age || Interesting || ||

| Joe User     |  25   |  False         |  |

| Suzie Smart |  18   |  False         |  |

| Jon Con      |  45   |  True          |  |

The Listview:

Core.UIItems.ListView lv = document.Get<Core.UIItems.ListView>("GridOne");

Assert.IsNotNull(lv);

Method One:

txtResult.Text = lv.Rows[0].Cells["Name"].Text;

Fails with an Object not set to an instance of an object error. 

Method Two:

ListViewCell b = lv.Rows[1].Cells["Name"];

Assert.IsNotNull(b);

Fails on the Assert test as it is NULL

I have tried several other methods with the same results.

 

Note: I’m able to get the header rows text, count rows, but I can seem to count the columns for any rows either.

 

Any ideas?

Thanks in advance,

 

Geremy

Sep 1, 2009 at 5:03 PM

Here is the code i'm running with some notes inline:

 

<font size="2">

Core.UIItems.

</font>

ListView lv = document.Get<Core.UIItems.ListView>("GridOne");Assert.IsNotNull(lv);//Count the header row

txtResult.Text +=

"\r\n Header columns = " + lv.Header.Columns.Count.ToString(); //Output: 3

txtResult.Text +=

"\r\n Header column 0 = " + lv.Header.Columns[0].Text; //Output: Name

txtResult.Text +=

"\r\n Header column 1 = " + lv.Header.Columns[1].Text; //Output: Age

txtResult.Text +=

"\r\n Header column 2 = " + lv.Header.Columns[2].Text; //Output: Interesting

txtResult.Text +=

"\r\n Rows = " + lv.Rows.Count.ToString(); //Output: 3

 

//Method 1

 

//Exception: {"Object reference not set to an instance of an object."}

 

//txtResult.Text = lv.Rows[1].Cells["Name"].Text;

 

//Method 2

 

//Exception: {"Error invoking ListView.Select"}

 

//Inner Exception: {"Object reference not set to an instance of an object."}

 

//lv.Select("Name", "Jon Con");

 

//Method 3

 

//Exception: {" Expected: not null\r\n But was: null\r\n"}

 

//ListViewRows rows = lv.Rows;

 

//ListViewCell b = lv.Rows[1].Cells["Name"];

 

//Assert.IsNotNull(b);

 

//Method 4

 

//Exception: {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}

 

//txtResult.Text = lv.Rows[1].Cells[1].Text;

 

//Method 5

 

//Exception: {"Object reference not set to an instance of an object."}

 

//txtResult.Text += "The Results Text is: " + lv.Cell("Name", 1).Text;

 

//Method 6

 

//Exception: {" Expected: not null\r\n But was: null\r\n"}

 

//ListViewCell lvC = lv.Cell("Name", 1);

 

//Assert.IsNotNull(lvC);

Sep 1, 2009 at 5:43 PM

Same here. The cells collection is always empty. This question is the same as http://white.codeplex.com/Thread/View.aspx?ThreadId=67513

Any insights greatly appreciated!

Coordinator
Sep 6, 2009 at 9:40 AM

have you checked this

http://white.codeplex.com/Wiki/View.aspx?title=Other%20questions

Sep 7, 2009 at 5:30 AM

I have looked at that, it didn't provide much help to me.  But I did find another way to solve this problem.  I'm working on the code, and I will post my solution in the next few days.  In short it is using: 'Core.UIItems.Finders'

Sep 10, 2009 at 4:23 AM

Here is the code I started playing with to meet my requirements.  This isn't the complete solution, but should give you enough to figure it out.

    var searchCriteria = SearchCriteria.ByAutomationId("myGridControl");
    var gridCells = Environment.window.GetElement(searchCriteria);


             var nameToSearchFor = "name property";
            Condition condition = new PropertyCondition(AutomationElement.NameProperty, nameToSearchFor);
           
            var availableValues = currentSystemsUsers.FindAll(TreeScope.Descendants, condition);


            Console.WriteLine("the available count: " + availableValues.Count);


            Console.WriteLine("The name of the element found is: " + availableValues[4].Current.Name);


            SelectionItemPattern listPattern = availableValues[4].GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
            listPattern.Select();

Coordinator
Sep 20, 2009 at 5:26 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jul 19, 2010 at 6:29 PM
Hello, I have the same problem with a silverlight 4 datagrid. Can you tell me where the "Environment.windows" and the "condition" objects do come from? What using directives to I have to insert? Ty!
Jul 22, 2010 at 12:48 PM

Hi

I ran into a similar problem. A quick solution maybe to simply change White.Core.UIItems.ListViewRow.cs.

public virtual ListViewCells Cells
        {
            get
            {
                actionListener.ActionPerforming(this);
                List<AutomationElement> collection = finder.Descendants(AutomationSearchCondition.ByControlType(ControlType.Text));
                return new ListViewCells(collection, actionListener, header);
            }
        }

 

Just change the finder method in the second line to Descandants. That seems to work for me so far. But no guarentees, this may have some side effects I haven't seen yet (think of data templates that contain multiple text boxes, my guess is that that each box would be threated as a single cell). Additionally, that only gives you text cells. This may need some extensions to get other common datagrid controls like check boxes or combo boxes.

Jul 23, 2010 at 10:39 AM

Great Job, thank you very much. This quickfix works for my purposes!

Aug 5, 2010 at 2:25 PM

The quickfix mentioned above does not seem to work for me. When changing the White Core to use finder.Descendants, I still cannot access any cells in a WPFDataGrid (ListView). It can see all the rows, columns, etc, just not any of the individual cells.

SearchCriteria ssearchCriteria = SearchCriteria.ByAutomationId("salesProductsVisGrid");
Core.UIItems.ListView table = window.Get<Core.UIItems.ListView>(ssearchCriteria);

in this example:

-> table.Rows.Count - returns 1

-> table.Header.Columns.Count - returns 6

-> table.Rows[0].Cells.Count - returns 0 although it should return 6 here.

Does anyone have any more suggestions? Thanks!