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

CellValidating event question

9 Answers 413 Views
GridView
This is a migrated thread and some comments may be shown as answers.
shortie
Top achievements
Rank 2
shortie asked on 27 Aug 2009, 02:05 AM
Hello,

We need help in the following issues:

1. When user inputs an invalid value for a cell, we can use ErrorText to show an error message in the RowHeaderColumn. Normally, the ErrorText will be cleared after the user corrects the value. Sometimes the user will just press Esc key to cancel the input value, in this case the CellValidating event won't get fired and the ErrorText will remain shown on the RowHeaderColumn. This behavior will make the user feel confused.

2. We often have many columns to be shown in the grid and the user can use horizontal scroll bar to scroll to the region (s)he likes. When the user scrolls to the right, the ErrorText icon will still show up when a cell receives invalid value. But there is no ErrorText tooltip when the user moves the mouse over the ErrorText icon.

3. We use HtmlViewDefine to arrange the columns in 2-row display. In this case, the row indicator and the columns will overlap with each other when the user scrolls the grid horizontally. And the ErrorText tooltip won't be shown as we described in the 2nd issues.

Thanks in advance.

BR/shortie

9 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 01 Sep 2009, 07:38 AM
Hi ChunChang,

Regarding your questions:

1. CellValidating event occurs only when a cell value is changed. In case when Esc is pressed, the value remains the same and no validation is needed. However, you can handle CellEndEdit event in this case and reset the ErrorText property.

2. I confirm that this is an issue. Thank you for reporting it. We will address it in our upcoming release. I have updated your Telerik points for this bug report.

3. This is a theme issue. You can work around it by using the ViewCellFormatting event:

((GridTableElement)this.radGridView1.GridElement).RowHeaderColumnWidth = 40; 
 
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement is GridRowHeaderCellElement && e.CellElement.RowElement is GridDataRowElement) 
    { 
        e.CellElement.DrawFill = true
        e.CellElement.GradientStyle = GradientStyles.Solid; 
        e.CellElement.BackColor = Color.White; 
        e.CellElement.ZIndex = 1000; 
    } 

I hope this helps. If you need further assistance, I will be glad to help.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
NORIS
Top achievements
Rank 1
answered on 24 Sep 2009, 01:51 PM
Hello Jack,
Regarding:  1. CellValidating event occurs only when a cell value is changed. In case when Esc is pressed, the value remains the same and no validation is needed. However, you can handle CellEndEdit event in this case and reset the ErrorText property.

I am doing an Add New Row.  The first two columns can not be null.  If no text is entered in the these columns the CellEndEdit is not fired, and obviously as you stated, the CellValidating is not either.  Even if I click in the cells and click out the CellEndEdit is not fired, so I am unable to update the ErrorText.  The grid allows the row to be added into the grid w/o text in these two columns.  Since I am using the DataSource as SQL data table It will get a data error when I try to update.
How do I not allow them not to leave the new row unless there is text in the first two columns?
If code is provided, please use VB.
Thank you.

After more testing I wanted to let you know that on the new row the DataError is fired if I click in a cell that can not be null.  If I do not enter the cell that can not be null the DataError is not fired.
0
Jack
Telerik team
answered on 26 Sep 2009, 06:10 AM
Hi NORIS,

This exception should not appear when using our latest release - Q2 2009 SP1. Could you please confirm that you are using this version? You can use RowValidating event to validate new rows. Here is a sample:

void radGridView1_RowValidating(object sender, RowValidatingEventArgs e) 
    GridViewNewRowInfo newRow = e.Row as GridViewNewRowInfo; 
    if (newRow != null && newRow.DataRowInfo != null
    { 
        if (((GridViewDataColumn)this.radGridView1.CurrentColumn).UniqueName == "Column0"
        { 
            if (this.radGridView1.ActiveEditor.Value == DBNull.Value) 
            { 
                e.Cancel = true
            } 
        } 
        else if (newRow.DataRowInfo.Cells[0].Value == DBNull.Value) 
        { 
            e.Cancel = true
        } 
    } 

Here, we access new row cell values by using the DataRowInfo property, which contains the row that is being added. However, when there is an active editor, its value is not yet saved and you should use ActiveEditor property to get the actual value. I admit that this is a little unintuitive and we will improve our API in one of our upcoming releases.

If you need further assistance, please write me back.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
NORIS
Top achievements
Rank 1
answered on 29 Sep 2009, 01:54 PM
Hi Jack,
Yes, I  am using Q2 2009 SP1.
This issue was answered by you in Support Ticket threadid=245874.
Thank you.
0
Jack
Telerik team
answered on 30 Sep 2009, 11:32 AM
Hi NORIS,

I am glad to hear that. If you have any other questions, feel free to contact me.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Subh
Top achievements
Rank 1
answered on 05 Oct 2009, 12:59 PM
Hi,
    How can the ErrorText be set at the cell level? The ErrorText property is missing at the cell level.

Thanks in Advance

Subha
0
Jack
Telerik team
answered on 07 Oct 2009, 07:23 AM
Hello Subh,

ErrorText is related to GridViewDataRowInfo and it can't be set at a cell level. However, you can use CellValidating or CurrentCellChanged events to update its value. Please, don't hesitate to write me if you have further questions.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ayman
Top achievements
Rank 1
answered on 18 Jun 2013, 02:28 PM
hi
What is the event fired when esc button pressed twice in rad gridview in winforms
and
Is there a away to check if the first row of the grid (row index [-1]) has a data in its cells
and still not entered to new row

thanks
0
Anton
Telerik team
answered on 21 Jun 2013, 01:39 PM
Hello Ayman,

Thank you for writing.

The event that is fired is when you press two times Esc button is KeyPress. However, if RadGridView is in edit mode on first key press, the CellEndEdit event will be fired and on the second key press the KeyPress event will be fired.

As to your second question, I am not sure that I fully understand your scenario following the provided information. Please open a new support ticket and send us a sample application that demonstrates the case and I will be glad to help further.

I am looking forward to your reply.

Regards,
Anton
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
shortie
Top achievements
Rank 2
Answers by
Jack
Telerik team
NORIS
Top achievements
Rank 1
Subh
Top achievements
Rank 1
Ayman
Top achievements
Rank 1
Anton
Telerik team
Share this question
or