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

WPF GridView Detect When Adding Empty Row

0 Answers 158 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 25 Aug 2013, 10:01 PM
Hi, I have:
1) Telerik 2013 Q2 SP1;
2) Entity Framework DB (Linq to MySql);
3) Simple table: FirstName(NotNull),  LastName(NotNull), Date(Null).
4) Checked for NULL (in MySQL DB and in my Project), i.e. both properties must be NotNull;
5) Made a row validation (it's working, but when I press ESC and then trying to edit another row => the TargetInvocationException fires or smth similar in files such as Cell....cs, Gridview.....cs - I even don't have it);
The question is how to prevent this?
Code:

private TestDB testDB;

public MainWindow()
{
InitializeComponent();
testDB = new testDBEntities();
radGridView.ItemsSource = testDB.Person;

}

private
void radGridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
       {
           e.NewObject = new Person();
           testDB.Persons.Add((Person)e.NewObject);
       }
        
           private void radGridView_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
       {
           if (e.EditAction == GridViewEditAction.Cancel)  return;
           if (e.EditOperationType == GridViewEditOperationType.Edit)
           {
                   testDB.SaveChanges();
                   radGridView.Rebind();
           }
           else if (e.EditOperationType == GridViewEditOperationType.Insert)
           {
               testDB.SaveChanges();
               radGridView.Rebind();
           }
       }

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Share this question
or