This is a migrated thread and some comments may be shown as answers.

RadGridView HeaderCells Reordered

13 Answers 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 24 Feb 2015, 09:40 AM
Hi
I have a coded step which loops through the HeaderRow.HeaderCells collection of a RadGridView in order to find a particular column.
The test is data-driven and after the 2nd iteration of the datasource some of the cells in HeaderCells collection get reordered and no longer reflects the actual grid.
The attached image shows the grid. In the application, the columns in the grid are reset/added on each iteration of the datasource, but the first three are always "*", "Report Date" and "AVA".
Below is part of the code in the coded step which displays the header cells along with their Index.
var grid = Applications.MizuhoIPVShellSYS2exe.IPV_Database_Tool.AvaCaptureGrid;
foreach(GridViewHeaderCell c in grid.HeaderRow.HeaderCells)
{
    Log.WriteLine(String.Format("hr[{0}]-{1}",c.Index,c.Text));
}
Below is the output from this step. As you can see the first two sets get the columns in correct order (* -> Report Date -> AVA), but subsequent steps get AVA -> Report Date -> *. And even the Index property is reordered.
'23/02/2015 16:34:19' - LOG: hr[0]-*
'23/02/2015 16:34:19' - LOG: hr[1]-Report Date
'23/02/2015 16:34:19' - LOG: hr[2]-AVA
'23/02/2015 16:34:19' - LOG: hr[3]-Close out costs
'23/02/2015 16:34:19' - LOG: hr[4]-Notes
'23/02/2015 16:34:19' - LOG: hr[5]-Capture Levels
'23/02/2015 16:34:19' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:34:35' - LOG: hr[0]-*
'23/02/2015 16:34:35' - LOG: hr[1]-Report Date
'23/02/2015 16:34:35' - LOG: hr[2]-AVA
'23/02/2015 16:34:35' - LOG: hr[3]-Model risk
'23/02/2015 16:34:35' - LOG: hr[4]-Notes
'23/02/2015 16:34:35' - LOG: hr[5]-Capture Levels
'23/02/2015 16:34:35' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:35:25' - LOG: hr[0]-AVA
'23/02/2015 16:35:25' - LOG: hr[1]-Report Date
'23/02/2015 16:35:25' - LOG: hr[2]-*
'23/02/2015 16:35:25' - LOG: hr[3]-MPU - Lower
'23/02/2015 16:35:25' - LOG: hr[4]-Notes
'23/02/2015 16:35:25' - LOG: hr[5]-Capture Levels
'23/02/2015 16:35:25' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:35:40' - LOG: hr[0]-AVA
'23/02/2015 16:35:40' - LOG: hr[1]-Report Date
'23/02/2015 16:35:40' - LOG: hr[2]-*
'23/02/2015 16:35:40' - LOG: hr[3]-Concentrated position
'23/02/2015 16:35:40' - LOG: hr[4]-Notes
'23/02/2015 16:35:40' - LOG: hr[5]-Capture Levels
'23/02/2015 16:35:40' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:36:06' - LOG: hr[0]-AVA
'23/02/2015 16:36:06' - LOG: hr[1]-Report Date
'23/02/2015 16:36:06' - LOG: hr[2]-*
'23/02/2015 16:36:06' - LOG: hr[3]-Close out costs
'23/02/2015 16:36:06' - LOG: hr[4]-Notes
'23/02/2015 16:36:06' - LOG: hr[5]-Capture Levels
'23/02/2015 16:36:06' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:36:20' - LOG: hr[0]-AVA
'23/02/2015 16:36:20' - LOG: hr[1]-Report Date
'23/02/2015 16:36:20' - LOG: hr[2]-*
'23/02/2015 16:36:20' - LOG: hr[3]-Model risk
'23/02/2015 16:36:20' - LOG: hr[4]-Notes
'23/02/2015 16:36:20' - LOG: hr[5]-Capture Levels
'23/02/2015 16:36:20' - LOG: hr[6]-Tolerance
 

Do you know why this is happening?

Are there any other properties I can use to locate the column I and interested in?

I am trying to reproduce in a demo app ....

Thanks,
Mike.

13 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 24 Feb 2015, 11:46 AM
I have reproduced this in the attached demo app and test.
It's related to the fact that the columns are removed and added on each iteration.
In this test, the column order consistently alternates between the two orders.
Thanks,
Mike.
0
Cody
Telerik team
answered on 24 Feb 2015, 04:56 PM
Hi Mike,

Where columns appear visually in the UI may be totally difference than the order they appear in the browsers DOM. This is because CSS can control the X/Y placement of UI elements on the screen. So in the DOM you can have columns in the order of A, B, C but in the UI see them in the order C, B, A or any other combination as controlled by the X/Y placement set by CSS.

I hope this clarifies what is happening.


Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mike
Top achievements
Rank 1
answered on 24 Feb 2015, 07:23 PM
Hi Cody
This is a WPF app. Does the same apply there?
If so, how can I reliably identify a column based on the its header?

Also, this does not happen if the columns are not re-added each on each iteration.

Thanks,
Mike.
0
Mike
Top achievements
Rank 1
answered on 24 Feb 2015, 07:56 PM
Hi Cody
Also, the Index property of the GridViewHeaderCell is changing (as shown in the output earlier). Surely this shouldn't change?
Mike.
0
Cody
Telerik team
answered on 24 Feb 2015, 08:51 PM
Hi Mike,

Actually yes, the Microsoft XAML UI run time engine will do this to you, You cannot control it. I've seen their run time engine do some strange things with the XAML Visual Tree, which is what we use for automating WPF applications. It makes automation very challenging, but there's no getting away from this fact.

To find the "right" column you have to iterate through all the column headers looking for some unique property such as the text name of the column you want, then record the index of the column you just found. You have to do this because the index can and will change at random on you. I've had to deal with this many times.


Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mike
Top achievements
Rank 1
answered on 25 Feb 2015, 09:19 AM
Hi Cody
That is exactly what I am doing but the Index is changing.
The code below is outputting the column header text and the Index:
foreach(GridViewHeaderCell c in grid.HeaderRow.HeaderCells)
{
    Log.WriteLine(String.Format("hr[{0}]-{1}",c.Index,c.Text));
}

and the output below shows the Index changing.
I am actually looking for the AVA column, which starts off at Index=2 and then changes to Index=0
'23/02/2015 16:34:35' - LOG: hr[0]-*
'23/02/2015 16:34:35' - LOG: hr[1]-Report Date
'23/02/2015 16:34:35' - LOG: hr[2]-AVA
'23/02/2015 16:34:35' - LOG: hr[3]-Model risk
'23/02/2015 16:34:35' - LOG: hr[4]-Notes
'23/02/2015 16:34:35' - LOG: hr[5]-Capture Levels
'23/02/2015 16:34:35' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:35:25' - LOG: hr[0]-AVA
'23/02/2015 16:35:25' - LOG: hr[1]-Report Date
'23/02/2015 16:35:25' - LOG: hr[2]-*
'23/02/2015 16:35:25' - LOG: hr[3]-MPU - Lower
'23/02/2015 16:35:25' - LOG: hr[4]-Notes
'23/02/2015 16:35:25' - LOG: hr[5]-Capture Levels
'23/02/2015 16:35:25' - LOG: hr[6]-Tolerance

You can see this in the demo app and test I provided.

If you have an alternate method of locating columns, please can you provide some sample code.

Thanks,
Mike.
0
Cody
Telerik team
answered on 26 Feb 2015, 12:59 AM
Hi Mike,

Yes, the index value is going to change when you start adding and deleting columns even if you're doing it in the same order. This cannot be helped. It's the Silverlight runtime engine messing with you. Once you add/delete a column you must iterate through the columns again to determine the new index value and use it during that iteration.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mike
Top achievements
Rank 1
answered on 27 Feb 2015, 03:10 PM
Hi Cody
That is what I am doing. I am looping through the columns on each iteration from the datasource (i.e. after each time the columns are re-added).
In my first post there is an image which shows the grid in question with one row. What I am trying to do is input a value into the AVA cell in the first row. So I first determine the Index of the AVA column and then use this to execute a click: 
GridViewCell cell = grid.Rows[0].Cells[<index of AVA column>];
cell.User.Click();
On the first and second iterations (shown in my first post) this works fine because AVA Index=2. On the third and subsequent iterations however, it clicks in the "*" column cell because the AVA Index is now 0. So the new Index value is no longer aligned with the cells. 
How can I achieve what I am trying to do?
Thanks,
Mike.
0
Cody
Telerik team
answered on 03 Mar 2015, 07:57 PM
Hello Mike,

So let me see if I understand your last message. Your code iterates through the column headers, finds AVA at index 2, then it immediately (without adding/deleting columns) tries to enter a value into the first row of column 2... only to discover that in the UI it's actually entering data in the "*" column?

That doesn't make sense to me. I have no idea how to overcome such a problem. I'll need a way to reproduce this locally so I can investigate what's happening under the covers and come up with a solution. In the meantime would you send me the entire code you're currently trying to use? I can at least review it for structure.


Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mike
Top achievements
Rank 1
answered on 04 Mar 2015, 09:23 AM
Hi Cody
No, that's not what is happening.
The application iterates over rows from a datasource. Within each of these datasource iterations it runs a coded step which iterates the column headers to try to find the AVA column. When it finds the AVA column, it obtains its Index and uses it to Click() into a cell in the AVA column (so that a value can be input).
The first datasource iteration works fine: the Index of the AVA column comes back as 2, and doing a Click() into cell 2 targets the correct cell below the AVA column.
Other datasource iterations don't work: the Index of the AVA column comes back as 0. When this Index is then used to Click() into the cell, it clicks into the cell below the "*" column.
I have already created a demo program and test which reproduces this issue. This demo is attached to my second post in this thread. In this demo, datasource iterations 1, 3, 5 etc are ok, but iterations 2, 4, 6 etc are exhibit the problem. The demo highlights the problem by logging the column headers and their Index values as shown below:
'23/02/2015 16:34:35' - LOG: hr[0]-*
'23/02/2015 16:34:35' - LOG: hr[1]-Report Date
'23/02/2015 16:34:35' - LOG: hr[2]-AVA
'23/02/2015 16:34:35' - LOG: hr[3]-Model risk
'23/02/2015 16:34:35' - LOG: hr[4]-Notes
'23/02/2015 16:34:35' - LOG: hr[5]-Capture Levels
'23/02/2015 16:34:35' - LOG: hr[6]-Tolerance
.
.
'23/02/2015 16:35:25' - LOG: hr[0]-AVA
'23/02/2015 16:35:25' - LOG: hr[1]-Report Date
'23/02/2015 16:35:25' - LOG: hr[2]-*
'23/02/2015 16:35:25' - LOG: hr[3]-MPU - Lower
'23/02/2015 16:35:25' - LOG: hr[4]-Notes
'23/02/2015 16:35:25' - LOG: hr[5]-Capture Levels
'23/02/2015 16:35:25' - LOG: hr[6]-Tolerance

Please run the demo and let me know if you can see the issue.

Thanks,
Mike.





0
Cody
Telerik team
answered on 04 Mar 2015, 10:13 PM
Hi,

So now I am confused what the technical problem is. I did run your sample application with sample test. All it proves is that the index order of the columns changes every time "click me" is pressed. The test still passes and I'm left wondering where/why your test is failing. Can you send me a test that actually fails that I can study?


Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mike
Top achievements
Rank 1
answered on 05 Mar 2015, 04:06 PM
Hi Cody
I have fixed my problem.
Whilst enhancing the demo to make the test fail I realised that I was using the Index value as a starting point and find the column next to it. What I didn't show in my post was that I was taking the Index of the AVA column and adding 1 to it because I needed to input the value in the next column. I got side-tracked by the changing Index weirdness.
Thanks for your help.
Mike.
0
Cody
Telerik team
answered on 05 Mar 2015, 08:03 PM
Hi Mike,

Excellent! Thank you for the update.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Cody
Telerik team
Share this question
or