event when Click here to add a new row

9 posts, 0 answers
  1. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 29 Sep 2012 Link to this post

    is there an event on a rad grid when the user clicks the "click here to add a new row"?  i can't find one.  I need to have that row visible and clickable, but i don't want it to really add one in the grid.  I want to do a pop up window to add the row and then when that window gets done, i'll manually add it to the dataset behind the grid.  i had another post where someone answered my question with doing custom user controls in the grid to edit data.  that worked great for most of my stuff, but now i have a situation where there are 3 columns in the grid, but the edit form needs to show about 60, so i want to do a popup winform and add a new one that way.  The rest of the grid will be non editable so it's just new rows.

    Thanks!
  2. Robert
    Robert avatar
    7 posts
    Member since:
    Jun 2012

    Posted 29 Sep 2012 Link to this post

    Hi John,

    I don't know if it's possible to do what you're asking with the RadGrid, but as an alternative could you put an 'Add New' button somewhere else on the form? That might be easier to implement and still give you exactly the functionality you describe.
  3. John
    John avatar
    60 posts
    Member since:
    Nov 2006

    Posted 30 Sep 2012 Link to this post

    yeah, i wish i could do that, it'd be easy, but they don't want to do it.  that's what they had in their old app and want to move to a grid only solution.  i could make a context menu and have my own right click, but it'd look better if i could catch the click on the add new row that was there and do what it wanted.
  4. Robert
    Robert avatar
    7 posts
    Member since:
    Jun 2012

    Posted 30 Sep 2012 Link to this post

    Understood. 

    I haven't tested this out, but there's a March 17, 2011 post by Richard Slade in this thread that might assist:

    http://www.telerik.com/community/forums/winforms/gridview/add-new-row---winforms-gridview-event.aspx

    Good luck!
  5. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 03 Oct 2012 Link to this post

    Hi guys,

    Thank you for writing.

    If I understand correctly, you need to capture the click of the new row and prevent adding rows with it. If so, here is how you can do that:
    void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
    {
        GridCellElement clickedCell = (GridCellElement)sender;
     
        if (clickedCell.RowElement is GridNewRowElement)
        {
            RadMessageBox.Show("New row is clicked");
        }
    }
     
    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        if (e.Row is GridViewNewRowInfo)
        {
            e.Cancel = true;
        }
    }

    I hope that you find this information useful.
     
    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  6. Taha
    Taha avatar
    1 posts
    Member since:
    Jun 2017

    Posted 29 Nov 2017 in reply to Stefan Link to this post

    Thank u :)
  7. Chris
    Chris avatar
    6 posts
    Member since:
    Jul 2016

    Posted 17 Oct 2018 in reply to Stefan Link to this post

    Hi Stefan,

    This works well for launching a dialog, which I use to add an item to the underlying DB. Then I update the datasource to include the added item (code below). After this the top row appears as empty (see screenshot). How can I get it to display "Click here to add new row" text again?

    private void grdCompanies_CellClick(object sender, GridViewCellEventArgs e)
    {
        var clickedCell = (GridCellElement)sender;
     
        if (clickedCell.RowElement is GridNewRowElement)
        {
     
            using (var companyForm = new CompanyForm())
            {
                companyForm.ShowDialog();
     
                grdCompanies.DataSource = null;
                grdCompanies.DataSource = DashboardDal.ListCompanies();
            }
        }
    }

     

     

    Cheers,

    Chris.

    P.S. Sorry for dragging up an old post!

  8. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 17 Oct 2018 Link to this post

    Hello John,

    You need to set the current row to null or another row:
    radGridView1.CurrentRow = null;

    I hope this will be useful. 

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  9. Chris
    Chris avatar
    6 posts
    Member since:
    Jul 2016

    Posted 17 Oct 2018 in reply to Dimitar Link to this post

    Thanks!
Back to Top