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

Set Child Row as CurrentRow

3 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simeon
Top achievements
Rank 1
Simeon asked on 19 Mar 2012, 12:58 PM
I have a hierarchic GridView and I want to select current row after refresh (datasource.AcceptChanges). So, when i do this all rows has collapsed and there is no child row selected. How can i save hierarchical expand state and current row in view of multiple grid templates?

3 Answers, 1 is accepted

Sort by
0
Accepted
Boryana
Telerik team
answered on 21 Mar 2012, 02:33 PM
Hi Simeon,

Thank you for contacting us.

To save rows' state information you will need to iterate through the Rows collection of every template and store the primary keys of all expanded rows. Once you have rows' unique IDs, you will be able to set their IsExpanded properties after the datasource is refreshed.

The attached sample project illustrates one possible implementation of the above approach. It also uses the same logic to save and restore the selected rows. 

I hope this helps. Do not hesitate to contact me if you encounter further issues.

Kind regards,
Boryana
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Simeon
Top achievements
Rank 1
answered on 21 Mar 2012, 06:08 PM
Hi Boryana,
Thank you for your quick and accurate response.
Firstly I would like to apologize for a little imprecise and unclear question on my part. This was due to lack of time and desire for a quick solutionIndeed, crawling on each row is the solution of the case and I got to this variant relatively quickly. Unfortunately I could not find a way to iterate all the templates without knowing the number and levels of the hierarchy stucture. So my new question is there a way to call the grid elements (templates), to get their count, current index and etc. and process them through some kind of looping stantmants, because I can not use grid.MasterTemplate.Templates(0).Templates(0)... without knowing their number.  In addition, I met some difficulties in scrolling to the child row and I shall be grateful if you tell me a quick and easy way to do this. My attempts were by:
GridTableElement gtElement = radgridview1.CurrentView;
gtElement.ScrollToRow(radgridview1.CurrentRow);

...but there is an error if the CurrentRow is not within the scope of MasterTemplate.
Thank you in advance!
Kind Regards,
Simeon 

 

0
Boryana
Telerik team
answered on 23 Mar 2012, 05:27 PM
Hello Simeon,

Thank you for writing back.

One possible approach for iterating the Templates of RadGridView is to create a custom IEnumerable<GridViewTemplates> class. Further, you can to store the unique row IDs of different templates in a common structure. I have modified my previous sample project, so that now it does not depend on the specific template tree structure. Please have a look at it and let me know whether it addresses the issue.

Also, I have added a method that also retrieves the current row of RadGridView. In the RestoreCurrentRow() method, there is a line that scrolls to the current row:
this.radGridView1.TableElement.ScrollToRow(row);

The above code seems to work regardless of the current row's template. However, if you encounter any issues or this approach does not work in your project, please let me know.

I hope this helps. Feel free to write back if you have further questions. I will do my best to assist you.

All the best,
Boryana
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Simeon
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Simeon
Top achievements
Rank 1
Share this question
or