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

what event(s) is/are fired when the pencil icon is clicked?

7 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim R
Top achievements
Rank 1
Tim R asked on 26 Nov 2012, 08:26 PM
When a cell editor has been invoked, and so the row is potentially "dirty", the pencil icon appears.  When the user clicks on the pencil, what event(s) is/are fired? 

I am handling the CurrentRowChanged event. But it's possible users will change a cell's value, then click the pencil, and then immediately close the form without moving to a different row.  In that case the CurrentRowChanged event does not fire, so I have to trap the pencil click and write any new changes to the database at that time as well.

Thanks

7 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 29 Nov 2012, 05:25 PM
Hello Tim,

Thank you for writing.

The following events occur during the editing process:
  • CellBeginEdit – Fires when the cell is about to enter edit mode. You can cancel edit mode at this stage by  setting the Cancel property to false.
  • CellEditorInitialized – Fires when the editor is initialized and visible.
  • CellEndEdit – Fires when the cell editing is finished.
  • ValueChanging – The active editor fires this event when it is about to change its value.
  • ValueChanged – Fires when the active editor changes its value. The data is not saved in the cell at this point.
  • CellValueChanged – Fires when the value of a cell has been changed.

In your scenario I would suggest using the CellEndEdit event, which will fire in the described scenario. However, I would suggest to re-consider whether you have to save this information or not when the cell is still in edit mode and the user attempt to close the form. Usually, such an action is interpreted as canceling the current changes - the changes in the edited cell.

Another suitable event is CellValidating which will prevent the user from closing the form until your validation passes. More information is available here: http://www.telerik.com/help/winforms/gridview-editors-data-validation.html.

I hope this will help. Feel free to write back with any further 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
Tim R
Top achievements
Rank 1
answered on 29 Nov 2012, 09:08 PM
Hello, Plamen. Thanks for the reply.

I do not save a row unless I can see the row in its entirety, to make sure that it "makes sense".  For that reason I'm using the RowValidating event as the place to examine the row and, if it is good, I save it.

I must disagree with you about the pencil icon: in many applications (notable example, Microsoft Access), a pencil icon signifies "Save the data". So when my users see a pencil icon, and click on it, they expect the data to be saved.  If they click on the pencil and then leave the form without visiting another row, the RowValidating event will not fire, and I cannot validate the row and save it, yet they will believe they have saved the row.

There really ought to be an event that fires when the user clicks on that "control cell" that contains the pencil icon.
Tim
0
Plamen
Telerik team
answered on 30 Nov 2012, 03:16 PM
Hello Tim,

Thank you for getting back to me.

As you noticed, the RowValidating event is fired only when the CurrentRow is changed, however, in your case when clicking the "pencil" icon, the current row is not changed, thus the RowValidating is not fired. A suitable event to cover this case is the CellValidating event which will be triggered when the "pencil" icon is clicked. This is also the behavior in MS Access that you observe - you will not be able to leave a cell with invalid value in it.

So, what I would suggest is to use the CellValidating event to perform your validation. This way you will ensure that you always have valid values in the grid.

If you insist on keeping your logic in the RowValidating event, I can suggest a small work around for this case - when the pencil is clicked, save the grid's CurrentRow, set it to null and then set it back to the saved row. This will trigger the RowValidating event and your logic will be executed. The downside of this approach is that the event will be triggered twice, because we change the CurrentRow twice.
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridRowHeaderCellElement rowHeader = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridRowHeaderCellElement;
    if (rowHeader != null)
    {
        GridViewRowInfo saveRow = radGridView1.CurrentRow;
        radGridView1.CurrentRow = null;
        radGridView1.CurrentRow = saveRow;
    }
}

I hope that the provided information addresses your question.

Regards,
Plamen
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Tim R
Top achievements
Rank 1
answered on 30 Nov 2012, 08:47 PM
Plamen, I appreciate your reply, but it is not a matter of my "insisting" to keep my logic in the RowValidating event. That is where it properly belongs. Even if each individual cell value is valid, it is possible that the COMBINATION of values might be invalid. Therefore, I must assess the row in its entirety, not after each cell has been edited.

Suppose you want to enfore this rule:

                   If  Region = East of Mississippi then Shipper must not be Acme Shipping

Any time there is rule-driven logic involving more than one cell, cell-level validation is not the way to go, and it is better to put the rule enforcement logic at the row level, not at the cell level.

So let me please restate this as a feature request:  When the pencil icon is clicked, there should be a PencilClicked event (or whatever you want to call it).  That event should fire ONLY WHEN the pencil icon is clicked.  Microsoft users expect the action to mean "save this row".

P.S. I am not suggesting that the CellValidating event should be forgotten.  It should occur too if applicable. When the pencil icon is clicked, any cell that was in edit mode should be validated,and then the row must be validated. The "save this row" action should invoke the row validation events.



0
Plamen
Telerik team
answered on 05 Dec 2012, 10:36 AM
Hello Tim,

Thank you for writing back.

I will I have added this as a feature request to our Public Issue Tracking System and we will consider its implementation in future. Feel free to add your vote for it here: http://www.telerik.com/support/pits.aspx#/public/winforms/13653

Your Telerik Points have been updated for this request.

Can you please let me know whether the work around with the change of the current row works in your case?

Greetings,
Plamen
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
KFC
Top achievements
Rank 1
answered on 11 Jul 2018, 03:06 PM

Hello there,

Is there any update on this? I am looking for this exact same feature or a way around

I've tried everything but need an event to fire after the record becomes "Undirty"

Cheers

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Jul 2018, 11:56 AM
Hello, Khurram,    

Since we have migrated our old Public Issue Tracking system to the feedback portal, you can refer to the following link in order to track the issue: https://feedback.telerik.com/Project/154/Feedback/Details/110682-add-radgridview-validate-the-entire-row-by-clicking-the-pencil-icon-in-the-gri

Currently, feel free to use the suggested workaround.

I hope this information helps. If you have any additional questions, please let me know.  
 
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Tim R
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Tim R
Top achievements
Rank 1
KFC
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or