Ruth Goldberg
Top achievements
Rank 1
Ruth Goldberg
asked on 23 Feb 2010, 03:26 PM
In my cellValidating event, I validate the field and set the errortext if invalid. However, if I am adding a new record, the row is not GridViewDataRowInfo, which has an errortext property, but GridViewNewRowInfo, which doesn't. Is there any way to set the errortext for the row?
4 Answers, 1 is accepted
0
Accepted
Hi Ruth Goldberg,
You can extend and replace GridRowHeaderCellElement to support error text for GridViewNewRowInfo row. You should subscribe to CreateCell event, where you have to replace the cell with its custom implementation. You can use the following code snippet as a sample:
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
You can extend and replace GridRowHeaderCellElement to support error text for GridViewNewRowInfo row. You should subscribe to CreateCell event, where you have to replace the cell with its custom implementation. You can use the following code snippet as a sample:
public
class
CustomGridRowHeaderCellElement : GridRowHeaderCellElement
{
public
CustomGridRowHeaderCellElement(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{
}
public
override
void
UpdateInfo()
{
base
.UpdateInfo();
if
(
this
.RowInfo
is
GridViewNewRowInfo)
{
if
(
this
.RowInfo.Tag ==
null
)
{
this
.ErrorImage.Image =
null
;
this
.ToolTipText = String.Empty;
}
else
{
this
.ToolTipText = Convert.ToString(
this
.RowInfo.Tag);
this
.ErrorImage.Image =
this
.TableElement.ErrorRowHeaderImage;
}
}
}
private
ImagePrimitive ErrorImage
{
get
{
if
(
this
.Children.Count == 0)
{
return
null
;
}
return
this
.Children[0]
as
ImagePrimitive;
}
}
}
this
.radGridView.CreateCell +=
new
GridViewCreateCellEventHandler(radGridView_CreateCell);
private
void
radGridView_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridRowHeaderCellElement))
{
e.CellType =
typeof
(CustomGridRowHeaderCellElement);
}
}
Finally, you need to only set the desired error text in the Tag property of GridViewNewRowInfo instance as it's shown in the following sample code:
private
void
radGridView_CellValidating(
object
sender, CellValidatingEventArgs e)
{
GridViewDataRowInfo dataRow = e.Row
as
GridViewDataRowInfo;
if
(dataRow !=
null
)
{
dataRow.ErrorText =
"This is error text"
;
}
else
if
(e.Row
is
GridViewNewRowInfo)
{
e.Row.Tag =
"This is error text"
;
}
}
Let us know if you need further assistance.
Regards,
Svettthe Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ruth Goldberg
Top achievements
Rank 1
answered on 25 Feb 2010, 04:21 PM
Thanks. I had to convert it to vb.net, but it worked.
0
Vijay
Top achievements
Rank 1
answered on 04 Oct 2013, 04:40 AM
Hi,
I'm having an unexpected issue and I'm sure I'm just missing something:
I have a bunch of grids, and I'm adding handling for UserAddingRow to these grids. If the key fields are already present in the rows of the RadGridView, then I alert the user. I have used e.cancel = true and e.rows(0).errortext set to the alert message.
The handling looks like this:
I'm having an unexpected issue and I'm sure I'm just missing something:
I have a bunch of grids, and I'm adding handling for UserAddingRow to these grids. If the key fields are already present in the rows of the RadGridView, then I alert the user. I have used e.cancel = true and e.rows(0).errortext set to the alert message.
The handling looks like this:
Private Sub rgCrew_UserAddingRow(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewRowCancelEventArgs) Handles rgCrew.UserAddingRow
Dim existsFlag As Boolean = false
'commented out logic that sets existsFlag
existsFlag = true
If existsFlag Then
Dim alertMessage As String = "Crew Template entry for Employee ID already exists. Please cancel the entry or update the key values."
MessageBox.Show(alertMessage, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2)
e.Cancel = True
e.Rows(0).ErrorText = alertMessage
End If
End Sub
In every grid but this one the red exclamation mark and error text hover is activated when the error scenario is triggered.
I've debugged both working and this versions so that the code for setting errorText does get touched.
Is there anything I might be missing that would not activate the errorText or suppress it?
I've debugged both working and this versions so that the code for setting errorText does get touched.
Is there anything I might be missing that would not activate the errorText or suppress it?
0
Hello Vijay,
Thank you for contacting us.
It appears that the code you provided me with works well on my end too. Maybe if you provide me with a project where the two working grids and the one non-working are I would be of bigger help.
I would recommend you open a new support ticket where attachments are allowed and you will be able to attach your project.
Let me know If there is anything else I can help with.
Regards,
George
Telerik
Thank you for contacting us.
It appears that the code you provided me with works well on my end too. Maybe if you provide me with a project where the two working grids and the one non-working are I would be of bigger help.
I would recommend you open a new support ticket where attachments are allowed and you will be able to attach your project.
Let me know If there is anything else I can help with.
Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>