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

Check if a row has changes

6 Answers 1383 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 10 Jul 2008, 04:51 PM
I am evaluating RadControls for WinForms, particularly the GridView and so far am impressed.  I was wondering though, is there a way to check if a row or cell is dirty, or has been changed?  It would be great if I could do this in the CurrentRowChanging event.

6 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 10 Jul 2008, 05:53 PM
I have also come across another issue.  I am setting a databound column's formatstring:

rgOpenCalls.Columns["entered_date"].FormatString = "{0:MM/dd/yyyy}";

This does a good job for display, but when I click on the cell to change the date,  get the long format (September 13, 2002).  It is the correct date, but the wrong format.  How do I make it show the same format as above.

One last thing, then I'll quit asking questions for a while...
How do I tell when a record has been deleted, updated or inserted? 
0
Martin Vasilev
Telerik team
answered on 11 Jul 2008, 04:24 PM
Hello Chris,

Thank you for the questions.

To check a new value when changin cell value in RadGridView you could use ValueChanging event:
private void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)  
{  
    if (e.NewValue.ToString() == "")  
    {  
        MessageBox.Show("Wrong value");  
    }  

To change the format date in the DataTime editor you could use the code-block below:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) 
    if (this.radGridView1.ActiveEditor is RadDateTimeEditor) 
    { 
        ((RadDateTimeEditor)this.radGridView1.ActiveEditor).CustomFormat = "MM/dd/yyyy"
    } 

To handle Adding, Removing and Updating rows in RadGridView you could use RowsChanged or RowsChanging events:
private void radGridView1_RowsChanged(object sender, GridViewCollectionChangedEventArgs e) 
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add) 
    { 
        MessageBox.Show("Row has been added!"); 
    } 

If you have other questions, do not hesitate to contact me again.

Best wishes,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris
Top achievements
Rank 1
answered on 14 Jul 2008, 01:30 PM
I can see the value of these events, but I'm not quite getting what I want...  What I am required to find as functionality in a grid is the ability to enter text in a cell, and then validate it... if it's invalid, then "e.cancel" and keep the user there.  I see where ValueChanging should work, but it's not firing when I leave the cell.  The same thing happens when I leave a row, the events don't seem to fire the way I need them.

What I need is:
1. an event that fires when a user leaves a cell, whether it's been changed or not.
2.  an event that fires when a user leaves a row, whether it's been changed or not.
3.  when these events fire, easily get the cell object's name, value, and ability to cancel.  These variables would be in the event args... but if there is an easy way to get these values outside of the event args, that would be ok too.

Are these possible?
0
Martin Vasilev
Telerik team
answered on 15 Jul 2008, 03:37 PM
Hello Chris,

Thank you for getting back to me.

Please find the answers in the same order:
  1. Unfortunately, there is not a clear way to catch and validate cell changing. By using RadGridView.Validating event you could check the new value and return the old one, but you cannot return in edit mode. We will add this functionality in some of the next release.
  2. You can use RadGridView.CurrentRowChanging event
  3. You can use RadGridView.CurrentCell property to access the changing cell.
If you need further assistance, do not hesitate to contact me again.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger Abderhalden
Top achievements
Rank 1
answered on 06 Nov 2009, 01:25 PM
Hi Martin

Actually I think the grid has still the same behaviour. Is it possible to validate the values of all fields in the current row, then if they have a problem I can display a messagebox to the user and go back in edit mode of the edited row.
If I create a new row with invalid values and then click on another row in the grid I can go to the DataError event and do my checks/message boxes but I cannot go back to the edit mode. The new row was lost.

Any ideas to resolve this problem?

Kind regards
Roger
0
Martin Vasilev
Telerik team
answered on 12 Nov 2009, 12:23 AM
Hi Roger Abderhalden,

Thank you for contacting us.

Actually, in the latest versions of RadGridView we have included new events such as CellValidated, CellValidating, RowValidated and RowValidating, that can handle validation scenarios. Please, find additional details in our documentation.

Do not hesitate to contact me again if you have any additional questions.

Best wishes,
Martin Vasilev
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.
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Martin Vasilev
Telerik team
Roger Abderhalden
Top achievements
Rank 1
Share this question
or