C#中对winform的控件datagridview直接进行编辑,修改,删除操作注意的地方
来源:互联网 发布:23code 项目源码 编辑:程序博客网 时间:2024/05/16 13:53
/// <summary>
/// 行数显错误时候验证
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
private void DgvGoodsInfo_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
if (DgvGoodsInfo.Rows[e.RowIndex].IsNewRow == true)
{
return;
}
else if (this.CellValid(DgvGoodsInfo, e.RowIndex) == true)
{
e.Cancel = false;
return;
}
else
{
e.Cancel = true;
return;
}
}
private bool CellValid(DataGridView dgv, int RowIndex)
{
//// 名称
if (dgv.Rows[RowIndex].Cells[this.ColumGoodsName.Name].ReadOnly)
{
return false;
}
if (dgv.Rows[RowIndex].IsNewRow == true)
{
return true;
}
//// TODO:编辑期间取值使用EditedFormattedValue进行判断
if (dgv[this.ColumGoodsName.Name, RowIndex].EditedFormattedValue == null || string.IsNullOrEmpty(dgv[this.ColumGoodsName.Name, RowIndex].EditedFormattedValue.ToString().Trim()))
{
WDMessageBox.ShowTips("清单货品名称不能为空");
dgv[this.ColumGoodsName.Name, RowIndex].ErrorText = "清单货品名称不能为空";
return false;
}
else
{
if (dgv[this.ColumGoodsName.Name, RowIndex].EditedFormattedValue.ToString().Trim().GetLength() > 50)
{
WDMessageBox.ShowTips("清单货品名称输入不能大于50个字符,一个汉字代表两个字符");
dgv[this.ColumGoodsName.Name, RowIndex].ErrorText = "清单货品名称输入不能大于50个字符,一个汉字代表两个字符";
return false;
}
if (this.bindlist != null && this.bindlist.Count > 0)
{
try
{
List<ExpOrderDetailModel> model = this.bindlist.Where(editmodel => editmodel.GoodsName.Equals(dgv[this.ColumGoodsName.Name, RowIndex].EditedFormattedValue.ToString().Trim(), StringComparison.CurrentCultureIgnoreCase)).ToList();
if (model.Count > 1)
{
WDMessageBox.ShowTips("清单货品名称必须唯一,如需添加,请修改货品件数");
dgv[this.ColumGoodsName.Name, RowIndex].ErrorText = "清单货品名称必须唯一,如需添加,请修改货品件数";
return false;
}
}
catch (Exception ex)
{
LoggingService.Error(ex.ToString());
}
}
}
}
/// <summary>
/// 单击单元格时触发-----删除操作
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
private void DgvGoodsInfo_CellClick(object sender, DataGridViewCellEventArgs e)
{
var dgv = sender as DataGridView;
var columnName = dgv.Columns[e.ColumnIndex].Name;
if (columnName == this.DeleteColumn.Name)
{
// dgv.RowValidating-=new DataGridViewCellCancelEventHandler(DgvGoodsInfo_RowValidating);
if (this.DgvGoodsInfo.CurrentRow.IsNewRow == false)
{
this.DgvGoodsInfo.EndEdit();
//// 新增情况下删除订单清单
if (string.IsNullOrEmpty(this.OrderID))
{
this.DgvGoodsInfo.Rows.RemoveAt(e.RowIndex);
}
//// 修改情况下删除订单清单
else
{
//this.DgvGoodsInfo.EndEdit();
if (dgv.Rows[e.RowIndex].Cells[this.MID.Name].Value == null)
{
this.DgvGoodsInfo.Rows.RemoveAt(e.RowIndex);
this.DgvGoodsInfo.DataSource = this.bindlist;
this.DgvGoodsInfo.EndEdit();
}
else
{
string strmid = dgv.Rows[e.RowIndex].Cells[this.MID.Name].Value.ToString();
//// 检测清单是否已经被提货
this.CheckGoodsInfoDel(strmid);
}
}
}
}
}
注意还需要在保存按钮的时候继续进行验证
- C#中对winform的控件datagridview直接进行编辑,修改,删除操作注意的地方
- C# WinForm中DataGridView的修改删除功能
- 基于C#的WinForm中DataGridView控件操作汇总
- WinForm中利用DataGridView控件对数据进行批量操作
- WinForm中利用DataGridView控件对数据进行批量操作
- C#对DataGridView中的数据进行添加、修改、删除操作
- 对DataGridView进行添加、修改、删除数据操作----C#
- C#对DataGridView进行添加修改删除操作
- C#对DataGridView进行添加、修改、删除数据操作
- c# WinForm开发 有关DataGridView控件数据库连接(存储和删除)的操作
- C# 对DataGridView控件的操作总结
- c# vs2005中datagridview控件和BindingManagerBase的应用(包括sqlDataAdapter.updata的添加修改删除操作)
- WinForm中DataGridView控件通过复选框实现多条记录的删除 c#2005
- C#对DataGridView中的数据进行添加、修改、删除操作c#操作datatable
- 对stl的set中元素进行删除时需注意的地方
- 对stl的set中元素进行删除时需注意的地方
- c# WinForm开发 DataGridView控件的各种操作总结
- c# WinForm开发 DataGridView控件的各种操作总结
- 构建高可扩Web架构和分布式系统实战
- memset、memset、strcpy函数详细说明
- android的文件操作
- 创建物化视图例子
- varchar2(10 byte)和varchar2(10 char)有什么不同
- C#中对winform的控件datagridview直接进行编辑,修改,删除操作注意的地方
- 黑马程序员—泛型
- SQL
- 《精通HTML5 + CSS3+JavaScript网页设计》
- 位运算1
- 结构体数组初始化
- 黑马程序员-java 枚举
- Myeclipse8.5中svn插件安装方法总结
- 笔记本