Set Child Row as CurrentRow

4 posts, 1 answers
  1. Simeon
    Simeon avatar
    6 posts
    Member since:
    Mar 2012

    Posted 19 Mar 2012 Link to this post

    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?
  2. Answer
    Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 21 Mar 2012 Link to this post

    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 >>
  3. Simeon
    Simeon avatar
    6 posts
    Member since:
    Mar 2012

    Posted 21 Mar 2012 Link to this post

    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 

     

  4. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 23 Mar 2012 Link to this post

    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 >>
Back to Top