Reloading a GridView dynamically

6 posts, 0 answers
  1. Dario
    Dario avatar
    8 posts
    Member since:
    Oct 2011

    Posted 26 Nov 2014 Link to this post

    I'm having an issue with the GridView. I'd like to be able to dynamically make appear the AddNewRow control. By default I set the  AllowAddNewRow=false, but if the user clicks on  The "Add New Row" menu item, I'd like for the NewRow control to appear on the grid, after I set the AllowAddNewRow=true. But I can not find a way to redraw or reload the entire grid for it to appear. Is this even possible?

    The gridview is on a form, do I have to reload the whole form for this work?

    I am using version 2014.2.715.40.

    Thanks for the help

    P.S. A little sample of the method called dynamically:

    public void New()
    {
     radGridPilotage.MasterTemplate.BeginUpdate();
     radGridPilotage.AllowEditRow = true;
     radGridPilotage.MasterTemplate.AllowAddNewRow = true;
     radGridPilotage.MasterTemplate.EndUpdate();
     radGridPilotage.Update();
    }
  2. Dario
    Dario avatar
    8 posts
    Member since:
    Oct 2011

    Posted 28 Nov 2014 in reply to Dario Link to this post

    I figured out the right way to do this. But now I am having trouble switching the AllowEditRow=True dynamically. Is this possible or is it only possible at design time?


    Thank-you
  3. Dimitar
    Admin
    Dimitar avatar
    2686 posts

    Posted 01 Dec 2014 Link to this post

    Hello Dario,

    Thank you for writing.

    You should be able to easily show/hide the add new row, and you do not need to use any Begin/End update blocks in this case:
    private void radButton1_Click(object sender, EventArgs e)
    {
        radGridView1.AllowAddNewRow = !radGridView1.AllowAddNewRow;
    }

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. Dario
    Dario avatar
    8 posts
    Member since:
    Oct 2011

    Posted 01 Dec 2014 in reply to Dimitar Link to this post

    Thank-you for the response Dimitri. To explain a little more my situation, The grid is on a form that is a child to a parent form. Now if I add a button on the child form, all works well. The problem is that the click actio is coming from the parent form. I found a work around for the AddNew. I basically add a new row to the binded Dataset then call the grid.Rows.AddNew() and it adds a new row to my grid, which is actually the wanted behavior.

    My new problem is trying to do the same with an Edit click on the parent form(in a menu). I found that you can turn the edit of a cell on or off on the CellClick action, but I need to know how, and if it's even possible, to find the index of the cell that is clicked. I would like to use this code, unless you know of a better way: 

            

    e.Row.Cells[cellIndex].BeginEdit();


    Thanks again for your help,
    Dario
  5. Dario
    Dario avatar
    8 posts
    Member since:
    Oct 2011

    Posted 01 Dec 2014 in reply to Dimitar Link to this post

    Rookie mistake. I just had to prefix my grid with "this." Now all works as it should. hanks for all your help Dimitar.
  6. Dimitar
    Admin
    Dimitar avatar
    2686 posts

    Posted 04 Dec 2014 Link to this post

    Hello Dario,

    Thank you for writing back.

    I am glad that everything is working fine on your side now. Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top