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

Deleting last row create new one

8 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 19 Dec 2012, 10:57 AM
Hello,

AllowDeleteRow = True;
AddNewRowPosition  = Bootom;

If you remove last row, grid will automatically create a new row (which is later validated) because the current selection will jump to the cell where there is a button (+Click here to add a new row) which adds a new row.

During the validation I'm not able to check whether the user actually wants to add a new row whether it was due to the removal.

The same situation occurs when I set AddNewRowPosition = Top and user will try to delete all rows.
After deleting last row, new one will be added.


How to avoid that? 

8 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 21 Dec 2012, 02:39 PM
Hi Dominik,

Thank you for writing.

I have tested the described scenarion and if you remove all grid rows a new row is not automatically added on my end. Just the grids' new row becomes current. Same is the behavior if the new row is positioned at the bottom and I delete the last data row. 

If you continue experiencing the undesired behavior, please get back to me with a sample application where it can be reproduced. Once I am able to do that I will be able to assist you with this case.

In the meantime you can check out the following documentation article, which describes useful events and properties allowing you to achieve different scenarios related to the new row: http://www.telerik.com/help/winforms/gridview-rows-new-row.html.

I hope this helps. Do not hesitate to contact us, If you have any additional questions.

All the best,
Plamen
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
konrad
Top achievements
Rank 1
answered on 06 Jan 2013, 01:32 PM
Thank you for your answer.
I understand how events work... but in my scenario i want to avoid situation when the grids's new row become current after deleting all rows.
Instead of entering edit mode I only want "Click here to add new row" row visible again.
0
Accepted
Plamen
Telerik team
answered on 07 Jan 2013, 11:10 AM
Hello Dominik,

Thank you for writing.

I managed to reproduce your scenario by following the supplied information. After deleting all rows, the grid's new row becomes current, thus the text is not displayed. If you want to avoid this situation, you could use the following code snippet to clear the current row:
radGridView1.UserDeletedRow += new GridViewRowEventHandler(radGridView1_UserDeletedRow);
 
void radGridView1_UserDeletedRow(object sender, GridViewRowEventArgs e)
{
    if (radGridView1.Rows.Count == 0)
    {
        radGridView1.CurrentRow = null;
    }
}

Attached you can find a sample project, which demonstrates the implemented scenario.

I hope you find my information useful.

Regards,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
konrad
Top achievements
Rank 1
answered on 08 Jan 2013, 08:55 AM
Thank you Plamen. This work great!
I have one more question.
Now needs to accomplish the same thing if the user adds a new row, but this event is not working:.

void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
{
    radGridView1.CurrentRow = null;
}

0
Plamen
Telerik team
answered on 11 Jan 2013, 06:35 AM
Hi Dominik,

Thank you for writing.

Use the following code snippet in order to achieve the desired scenario:
radGridView1.UserAddedRow += new GridViewRowEventHandler(radGridView1_UserAddedRow);
radGridView1.MasterTemplate.SelectLastAddedRow = true;
 
void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
{
    radGridView1.CurrentRow = null;
}

I hope this helps. If you have any additional questions, I will be glad to assist you.

Greetings,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
konrad
Top achievements
Rank 1
answered on 11 Jan 2013, 10:08 AM
Hi Plamen,

Thank you for your answer, unfortunately, still does not work for me.

Please check attached files:
1 - tab and 2 - click are working good.
3 - click on group and 4 - click on other control are not working.

So basically when validation ends within MasterTemplate it working good.... but not when you trying to leave grid at the end on entering data. This should work regardless of how the user finished adding a new row.



0
Accepted
Plamen
Telerik team
answered on 16 Jan 2013, 09:20 AM
Hi Dominik,

Thank you for writing.

I managed to reproduce your scenario by following the supplied screen shots. In order to avoid a situation when the RadGridView's new row become current after adding a new row, you can use a Timer and set the CurrentRow property of the RadGridView to null:
void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
{
    Timer timer = new Timer();
    timer.Tick += new EventHandler(timer_Tick);
    timer.Interval = 100;
    timer.Start();
}
 
void timer_Tick(object sender, EventArgs e)
{
    Timer timer = (Timer)sender;
    timer.Stop();
    timer.Dispose();
 
    radGridView1.CurrentRow = null;
}

Find attached a modified version of my previous sample project, which I hope will help you.

Should you have any future questions, do not hesitate to contact us.

Kind regards,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
konrad
Top achievements
Rank 1
answered on 23 Jan 2013, 09:11 AM

Works like a charm!
Thanks for your help.

Tags
GridView
Asked by
konrad
Top achievements
Rank 1
Answers by
Plamen
Telerik team
konrad
Top achievements
Rank 1
Share this question
or