Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I actually want the wpf equivalent for DataGridViewDataErrorEventArgs and DataGridDataErrorContexts....


C#
private void HandleDataError(object sender, DataGridDataErrorEventArgs e)
       {
           System.Windows.Controls.DataGrid dg = (System.Windows.Controls.DataGrid)sender;
           DataGridColumn dc = dg.Columns[e.ColumnIndex];
           if ((e.Context & DataGridDataErrorContexts.Parsing) == DataGridDataErrorContexts.Parsing)
           {
               if (dc.ValueType == typeof(Int32))
               {
                   System.Windows.MessageBox.Show(this, "Invalid number for " + dc.HeaderText, "Input error", MessageBoxButton.OK, MessageBoxImage.Warning);
               }
               else
               {
                   System.Windows.MessageBox.Show(this, "Invalid format for " + dc.HeaderText, "Input error", MessageBoxButton.OK, MessageBoxImage.Warning);
               }
           }
           //else if ((e.Context & DataGridViewDataErrorContexts.Commit) == DataGridViewDataErrorContexts.Commit)
           //{
           //    MessageBox.Show(this, "You must enter a value for " + dc.HeaderText, "Input error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
           //    return;
           //}
           else
               System.Windows.MessageBox.Show(this, e.Exception.Message, "Input error", MessageBoxButton.OK, MessageBoxImage.Warning);
       }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900