日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

获取WPF的DataGrid控件中,是否存在没有通过错误验证的Cell

發(fā)布時(shí)間:2023/12/20 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取WPF的DataGrid控件中,是否存在没有通过错误验证的Cell 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C# code ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ????????///?<summary> ????????///?獲取DataGrid的所有行是否存在驗(yàn)證錯(cuò)誤。 ????????///?</summary> ????????///?<param?name="dg">要檢查的DataGrid實(shí)例</param> ????????///?<returns>true?有錯(cuò),false?無錯(cuò)</returns> ????????public?static?bool?GetDataGridRowsHasError(DataGrid?dg) ????????{ ????????????bool?hasError?=?false?; ????????????for?(int?i?=?0;?i?<?dg.Items.Count;?i++) ????????????{ ????????????????DependencyObject?o?=?dg.ItemContainerGenerator.ContainerFromIndex(i); ????????????????hasError?=?Validation.GetHasError(o); ????????????????if?(hasError) ????????????????{ ????????????????????break; ????????????????} ????????????} ????????????return?hasError; ????????}


判斷有驗(yàn)證錯(cuò)誤?就不執(zhí)行提交。

C# code ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 ///?<summary> ????????///?獲取DataGrid的第一個(gè)被發(fā)現(xiàn)的驗(yàn)證錯(cuò)誤結(jié)果。 ????????///?</summary> ????????///?<param?name="dg">被檢查的DataGrid實(shí)例。</param> ????????///?<returns>錯(cuò)誤結(jié)果。</returns> ????????public?static?ValidationError?GetDataGridRowsFirstError(DataGrid?dg) ????????{ ????????????ValidationError?err=null; ????????????for?(int?i?=?0;?i?<?dg.Items.Count;?i++) ????????????{ ????????????????DependencyObject?o?=?dg.ItemContainerGenerator.ContainerFromIndex(i); ????????????????bool?hasError?=?Validation.GetHasError(o); ????????????????if?(hasError) ????????????????{ ????????????????????err?=?Validation.GetErrors(o)[0]; ????????????????????break; ????????????????} ????????????} ????????????return?err; ????????} ????????///?<summary> ????????///?執(zhí)行檢查DataGrid,并提示第一個(gè)錯(cuò)誤。重新定位到錯(cuò)誤單元格。 ????????///?</summary> ????????///?<param?name="dg">被檢查的DataGrid實(shí)例。</param> ????????///?<returns>true?有錯(cuò)并定位,false?無錯(cuò)、返回</returns> ????????public?static?bool?ExcutedCheckedDataGridValidation(DataGrid?dg) ????????{ ????????????ValidationError?err?=?GetDataGridRowsFirstError(dg); ????????????if?(err?!=?null) ????????????{ ????????????????string?errColName?=?((System.Windows.Data.BindingExpression)err.BindingInError).ParentBinding.Path.Path; ????????????????DataGridColumn?errCol?=?dg.Columns.Single(p?=> ????????????????{ ????????????????????if?(((Binding)((DataGridTextColumn)p).Binding).Path.Path?==?errColName) ????????????????????????return?true; ????????????????????else?return?false; ????????????????}); ????????????????//string?errRow?=?((DataRowView)((System.Windows.Data.BindingExpression)err.BindingInError).DataItem)["SWH"].ToString(); ????????????????//dg.Items.IndexOf(((System.Windows.Data.BindingExpression)err.BindingInError).DataItem); ????????????????dg.SelectedItem?=?((System.Windows.Data.BindingExpression)err.BindingInError).DataItem; ????????????????int?errRowIndex?=?dg.SelectedIndex; ????????????????MessageBox.Show(string.Format("第\"{0}\"行?的\"{1}\"列的單元格數(shù)據(jù)不合法(以紅色標(biāo)出),請?zhí)顚懻_后再執(zhí)行其他操作。",?errRowIndex?+?1,?errCol.Header),?"系統(tǒng)消息",?MessageBoxButton.OK,?MessageBoxImage.Warning); ????????????????dg.CurrentCell?=?new?DataGridCellInfo(dg.SelectedItem,?errCol); ????????????????if?(!((DataRowView)dg.CurrentItem).IsEdit) ????????????????{ ????????????????????((DataRowView)dg.CurrentItem).BeginEdit(); ????????????????} ????????????????TextBox?txt?=?dg.CurrentColumn.GetCellContent(dg.CurrentItem)?as?TextBox; ????????????????txt.Focus(); ????????????????return?true; ????????????} ????????????else ????????????{ ????????????????return?false; ????????????} ????????}

轉(zhuǎn)載于:https://www.cnblogs.com/sjqq/p/8032201.html

總結(jié)

以上是生活随笔為你收集整理的获取WPF的DataGrid控件中,是否存在没有通过错误验证的Cell的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。