Validating rows when using LINQ to SQL
来源:互联网 发布:网络无武侠小说 编辑:程序博客网 时间:2024/06/06 02:31
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using DevExpress.XtraGrid;using DevExpress.XtraEditors;using DevExpress.XtraGrid.Columns;using System.Data.Linq;namespace WindowsFormsApplication51 { public partial class Form1 : Form { DataClasses1DataContext d = new DataClasses1DataContext(); CurrencyManager c; public Form1() { InitializeComponent(); gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Top; gridView1.RowUpdated += new DevExpress.XtraGrid.Views.Base.RowObjectEventHandler(gridView1_RowUpdated); bindingSource1.DataSource = d.Products.ToList(); } bool ifValid = true; void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { try { if (e.RowHandle == GridControl.NewItemRowHandle) d.Products.InsertOnSubmit((Product)e.Row); d.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict); } catch (Exception ex) { // refresh data bindingSource1.DataSource = null; d.Dispose(); d = new DataClasses1DataContext(); bindingSource1.DataSource = d.Products.ToList(); BeginInvoke(new Action(() => { gridView1.FocusedRowHandle = e.RowHandle; gridView1.SetColumnError(null, ex.Message); if (e.RowHandle == GridControl.NewItemRowHandle) { gridView1.AddNewRow(); } // if you want to keep user changes PropertyDescriptorCollection props = TypeDescriptor.GetProperties(e.Row); foreach (GridColumn col in gridView1.VisibleColumns) { PropertyDescriptor prop = props.Find(col.FieldName, false); if (prop != null) gridView1.SetFocusedRowCellValue(col, prop.GetValue(e.Row)); } })); } } void c_ListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemAdded) { Product p = c.List[e.NewIndex] as Product; } } void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { e.Valid = ifValid; } private void simpleButton1_Click(object sender, EventArgs e) { try { d.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict); } catch(Exception){ d.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, d.Products); gridControl1.RefreshDataSource(); gridView1.FocusedRowHandle = GridControl.NewItemRowHandle; gridView1.FocusedRowHandle = 1; } } }}
0 0
- Validating rows when using LINQ to SQL
- LINQ to SQL系列Part 1 - Using LINQ to SQL
- LINQ to SQL系列Part 8 - Using LINQ to SQL
- Using LINQ to SQL (Part 1)
- Using LINQ to SQL (Part 1)
- linq to sql case when 语句的实现
- 'Your application bundle must install to “/Applications”' when validating archive
- linq,linq to sql
- Effective Using LINQ To SQL (1) - 分頁技巧
- Using SQLMetal code generator tool for LINQ to SQL
- LINQ to SQL系列Part 9-Using a Custom LINQ Expression with the control
- Linq初探--Linq to SQL
- Validating Checkboxlist using CustomValidator
- How to delete duplicate rows with SQL
- How to find duplicate rows with SQL
- LINQ to SQL 学习
- 什么是Linq to sql
- 使用LINQ to SQL
- 虚函数与纯虚函数的作用和区别
- Android2.3使用BitmapRegionDecoder获取指定区域的图片
- static关键字的作用
- 由malloc等函数想到的一些问题
- C语言相关Warning。。。解决方案
- Validating rows when using LINQ to SQL
- php处理linux配置文件问题
- DWR入门实例(二)
- C# 中反射的介绍
- js 执行顺序
- modelsim-win64-10.1c-se.exe安装备忘
- 南京邮电大学课程设计——加速度检测应用
- 记录两个小工具:
- ios禁用多按钮同时点下的bug