How to set values in a grid using cell row and column number?

Apr 17, 2014 at 11:57 PM

Can you detail some examples of how to set values in a grid? I see examples how to get the values of a table, including number of rows and columns, and how to address each individual grid cell to obtain the values.

However, I dont find a good example of how to set the values in a data grid, particularly when addressing the cell by row and grid number. The grid has mutiple rows and cells.

For example, I can get the following table and its specific cells:
    $grid=( ... | Get-UiaDataGrid -Class 'DataGridTable' )
    $table1rowcount=$grid.GridRowCount ;
    $table1columncount=$grid.GridColumnCount ;
and either of these will return the text in cell 0,0:
    ($itemtext=$grid.GetItem(0,0) | Invoke-UIAValuePatternGet)
    ($itemtext=($grid.GetItem(0,0)) | Get-UiaDataItemText) 
But how to set a value. I could not find a SetItem method.

I find neither of the following sets a value:
    (($grid.GetItem(0,0)) | Set-UIAControlKeys -Text "4")   
    (($grid.GetItem(0,0)) | Set-UIAFocus | Set-UIAControlKeys -Text "4") 
unless I click into the cell first.

So to get anything to work I need to all of the following...
    (($grid.GetItem(0,0)) | Set-UiaFocus) 
    (($grid.GetItem(0,0)) | Invoke-UiaListItemClick) 
    (($grid.GetItem(0,0)) | Set-UIAControlKeys -Text "4")
but there is a big problem. The text actually ends up in the wrong cell. Usually in cell 2,0 not cell 0,0. I see the mouse hover over the 0,0 cell, but the text goes into the 2,0 cell. (That I need to click into the cell first might be a peculiarity of the grid I am automating. )
I see some examples of using Get-UiaDataItem as in:
    $dataitems=($grid | Get-UiaDataItem)
    foreach ($item in $dataitems) { ...
but in this case, how to address the specific $item (cell) by row and column number? Attempting to address the cells by name won't work, as they are all pre-populated with the same value.
So, what is/are the appropriate way[s] to set the values in a data grid when addressing the cell by row and grid number?
Oct 31, 2014 at 3:49 AM
Here's an ASP.NET control suite with a gridview control included, which provides details for column and row customization, including corresponding sample codes. See if this might help.