如何使用Datagrid处理Dataerror事件并使用Wpf?我这样做是因为我将它从窗体转换为Wpf。 [英] How Do I Handle A Dataerror Event With Datagrid And I Am Using Wpf? I Am Doing This Because I'm Converting It From Window Forms To Wpf.

查看:56
本文介绍了如何使用Datagrid处理Dataerror事件并使用Wpf?我这样做是因为我将它从窗体转换为Wpf。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上想要DataGridViewDataErrorEventArgs和DataGridDataErrorContexts的wpf等价物....





I actually want the wpf equivalent for DataGridViewDataErrorEventArgs and DataGridDataErrorContexts....


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);
       }

推荐答案

这篇关于如何使用Datagrid处理Dataerror事件并使用Wpf?我这样做是因为我将它从窗体转换为Wpf。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆