Hi,
I have this problem:
In a Form with a RadDock, in this RadDock two ToolWindows with one button each and two DocumentWindows. In a DocumentWindow, a RadGridView.
The RadGridView is with the event UserAddingRow:
private
void
RadGridView1_UserAddingRow(
object
sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e)
{
if
(e.Rows.Count() > 0 && e.Rows[0].Cells[
"Id"
].Value ==
null
)
{
e.Cancel =
true
;
this
.radGridView1.GridNavigator.Select(
this
.radGridView1.MasterView.TableAddNewRow,
this
.radGridView1.Columns[
"Id"
]);
this
.radGridView1.BeginEdit();
}
}
If you are editing a new row in the RadGridView with the value of "Id" null and you click on a button or in the tab of the other DocumentWindow, you don't stay in the new row. And the UserAddingRow event is fired many time.
Why? How to edit the column "Id" of the new row if you validate by clicking in other control?
11 Answers, 1 is accepted
Thank you for writing.
I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.
I have also updated your Telerik points.
Currently, the possible solution that I can suggest is to RowValidating event instead:
private
void
radGridView1_RowValidating(
object
sender, Telerik.WinControls.UI.RowValidatingEventArgs e)
{
if
(e.Row
is
Telerik.WinControls.UI.GridViewNewRowInfo && e.Row.Cells[
"Id"
].Value ==
null
)
{
this
.radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
this
.radGridView1.CurrentRow =
this
.radGridView1.MasterView.TableAddNewRow;
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Progress Telerik
Thank you for your quick response, but I have the same problem with the event RowValidating. It is triggered several times as you can see in the attached GIF. And we do not stay in the new line.
If we uncomment the last two lines of the code that follows, then we freeze the edition of the radgridview.
private
void
radGridView1_RowValidating(
object
sender, Telerik.WinControls.UI.RowValidatingEventArgs e)
{
if
(e.Row
is
Telerik.WinControls.UI.GridViewNewRowInfo && e.Row.Cells[
"Id"
].Value ==
null
)
{
Console.WriteLine(
"RowValidating"
);
this
.radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
this
.radGridView1.CurrentRow =
this
.radGridView1.MasterView.TableAddNewRow;
//this.radGridView1.GridNavigator.Select(this.radGridView1.MasterView.TableAddNewRow, this.radGridView1.Columns["Id"]); //this.radGridView1.BeginEdit();
}
}
Thank you for writing back.
I was able to replicate the multiple firing of the RowFormatting event. An alternative solution that I can suggest is to use the CellValidating event. Thus, you will be stuck in the cell once it is focused until you enter a valid value:
private
void
radGridView1_CellValidating(
object
sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
{
Console.WriteLine(
"CellValidating"
);
if
(e.Column.Name ==
"Id"
&& e.Value ==
null
)
{
e.Cancel =
true
;
if
(e.Row
is
Telerik.WinControls.UI.GridViewNewRowInfo)
{
this
.radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
}
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
For the CellValidating unfortunately it does the same thing, several calls to CellValidating when we go through the e.cancel and then the form is no longer accessible. You can see it in the .gif attached to this post.
Do you think the fix will be quickly found because this way of using Telerik objects is necessary.
Thank you for writing back.
Yes, indeed I meant RowValidating event. As to the CellValidating event, it is fired each time you try to exit the cell. It is normal behavior. When the new row becomes current you can change the current column to "Id". Thus, you won't be able to exit the cell until a valid value is entered.
I can't give you an exact timeframe when the issue will be addressed. You can track its progress, subscribe for status changes and add your comments on the following link: https://feedback.telerik.com/Project/154/Feedback/Details/240120-fix-radgridview-useraddingrow-is-fired-multiple-times-when-the-grid-is-inside
We will do out best to introduce a fix as soon as possible.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
I don't think CellValidating work fine, because when you change the column in the new row from "name" to "Id" it fired one. But when you change the column in the new row from "Id" to "name" it fired twice and freeze the form.
And when you change the column in the new row from "Id" to the button "Button1", it fired 4 times.
I wait for the fix
Thank you for writing back.
After performing some tests, I was able to replicate the multiple firing of the CellValidating event. I have updated the feedback item with a note to include this case as well. Unfortunately, the issue is at a location that is too deep for any customization to have an effect on it. Currently, the possible solution that I can suggest is to cancel the CellValidating event without using the TableAddNewRow.CancelAddNewRow method. Thus, you will be stuck in the invalid cell. If you press Escape, the new row will be rejected. Indeed, the event may be fired multiple times, but you can keep the last cell that triggered the event and if the last value is identical. In this case, you won't notify the user a second time for the invalid input.
We will do our best to introduce a fix as soon as possible.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Could we know at what point is the correction of this problem, it's already been a year and we are starting to need it quickly?
Thank you for your reply,
best regard
The status of the feedback item indicates that a fix hasn't been introduced yet. Please allow me to explain how we prioritize the issues that our users report. We are taking into consideration the following key points:
• Is the reported issue a show-stopper;
• Does the reported issue have a work-around;
• What is the severity and nature of the issue (for example – memory leak issue, performance issue, functionality issue, styling issue);
• How many users have reported the issue / How many users have voted for a feedback item.
Since there is a workaround for the RadGridView editor issue that you experience and there are other issues which require more urgent fixes, your issue is still not addressed. If more customers vote for it, we will increase its priority.
Meanwhile, feel free to use the suggested workaround. Ensure that you follow the item. Thus, you will get notified once the item is changed.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Hi,
The workaround is not good for us. I took the example of verification on a single column but it is on several columns that we must do the verification when the user must add a new line.
Thank's for your response
Best Regard
The RowValidating event allows you validate the whole row. You can iterate all cells in the row element and determine whether to cancel the validation. Additional information how it works is available in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/editors/data-validation
Your question has already been answered in the support thread you have opened on the same topic. Please, see our answer there for more information.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik