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

event when Click here to add a new row

8 Answers 254 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 29 Sep 2012, 04:17 PM
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!

8 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 29 Sep 2012, 07:08 PM
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.
0
John
Top achievements
Rank 1
answered on 30 Sep 2012, 04:35 PM
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.
0
Robert
Top achievements
Rank 1
answered on 30 Sep 2012, 09:37 PM
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!
0
Stefan
Telerik team
answered on 03 Oct 2012, 01:09 PM
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 >>
0
Taha
Top achievements
Rank 1
answered on 30 Nov 2017, 02:39 AM
Thank u :)
0
DBE
Top achievements
Rank 1
answered on 17 Oct 2018, 11:25 AM

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!

0
Dimitar
Telerik team
answered on 17 Oct 2018, 12:39 PM
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 and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
DBE
Top achievements
Rank 1
answered on 17 Oct 2018, 02:02 PM
Thanks!
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
John
Top achievements
Rank 1
Stefan
Telerik team
Taha
Top achievements
Rank 1
DBE
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or