gridview单元格编辑添加数据
行号
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
if (e.Info.IsRowIndicator)
{
if (e.RowHandle >= )
{
e.Info.DisplayText = (e.RowHandle + ).ToString();
}
else if (e.RowHandle < && e.RowHandle > -)
{
e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
e.Info.DisplayText = "G" + e.RowHandle.ToString();
}
}
}
声明数据源
private BindingList<InvoiceDetail> DataSource;//发票数据源
//初始化数据源
private void frmAddindent_Load(object sender, EventArgs e)
{
this.outTaskListLog.RefreshParent += new RefreshParentHandler((object obj) => { SetForm((OutRequest)obj); });
DataSource = new BindingList<InvoiceDetail>();
dvginfo.DataSource = DataSource;
}
添加新行事件
private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
InvoiceDetail invoiceData = gridView1.GetRow(e.RowHandle) as InvoiceDetail;
invoiceData.Price = ;
invoiceData.Amount = ;
invoiceData.Currency = cbDeclaredCurrency.Text;
invoiceData.Quantity = ;
invoiceData.QuantityUnit = "PCS";
invoiceData.OriginCountryCode = "CN";
}
单元格值,验证,离开事件
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (gridView1.FocusedRowHandle >= || gridView1.IsNewItemRow(gridView1.FocusedRowHandle))
{
if (e.Column.FieldName.Equals("Quantity") || e.Column.FieldName.Equals("Price"))
{
int i = ;
if (gridView1.GetFocusedRowCellValue("Quantity") != null)
{
i = (int)gridView1.GetFocusedRowCellValue("Quantity");
}
decimal d = ;
if (gridView1.GetFocusedRowCellValue("Price") != null)
{
d = Common.Utils.ObjToDecimal(gridView1.GetFocusedRowCellValue("Price"), );
}
decimal dec = i * d;
//设置结果值
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["Amount"], dec);
//gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["NumberOfPieces"], e.RowHandle + 1);
}
if (e.Column.FieldName.Equals("Amount"))
{
decimal dAmount = DataSource.Sum(s => s.Amount);
txtDeclared.Text = dAmount.ToString();
}
}
}
private void gridView1_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
{
if (gridView1.GetFocusedRowCellValue("Description") == null || string.IsNullOrWhiteSpace(gridView1.GetFocusedRowCellValue("Description").ToString()))
{
//gridView1.SetFocusedValue(gridView1.GetFocusedRowCellValue(""));
return;
}
if (gridView1.GetFocusedRowCellValue("Quantity") == null || gridView1.GetFocusedRowCellValue("Quantity").ToString() == "0")
{
//gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
return;
}
if (gridView1.GetFocusedRowCellValue("Price") == null || gridView1.GetFocusedRowCellValue("Price").ToString() == "0")
{
return;
}
if (gridView1.GetFocusedRowCellValue("Amount") == null || gridView1.GetFocusedRowCellValue("Amount").ToString() == "0")
{
return;
}
} private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
if (e.Value == null)
{
e.Value = "";
}
string reply = "";
int ireply = -1;
decimal dreply = -1;
if (gridView1.FocusedColumn.FieldName == "Description")
{
if (string.IsNullOrWhiteSpace(e.Value.ToString()))
{
reply = "品名不能为空。";
}
}
if (gridView1.FocusedColumn.FieldName == "Quantity")
{
if (int.TryParse(e.Value.ToString(), out ireply))
{
if (ireply <= 0)
{
reply = "物品数量必须大于零";
}
}
else
{
reply = "物品数量需要输入整数";
} } if (gridView1.FocusedColumn.FieldName == "Price")
{
if (decimal.TryParse(e.Value.ToString(), out dreply))
{
if (dreply <= 0)
{
reply = "单件必须大于零";
}
}
else
{
reply = "单件需要输入数字";
}
} if (gridView1.FocusedColumn.FieldName == "Amount")
{
if (decimal.TryParse(e.Value.ToString(), out dreply))
{
if (dreply <= 0)
{
reply = "金额必须大于零";
} }
else
{
reply = "金额需要输入数字";
}
} if (!string.IsNullOrWhiteSpace(reply))
{
e.ErrorText = reply.ToString();
e.Valid = false;
}
} AppearanceDefault appError = new AppearanceDefault(Color.White, Color.LightCoral, Color.Empty, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
object val = gridView1.GetRowCellValue(e.RowHandle, e.Column);
if (gridView1.IsNewItemRow(e.RowHandle))
{
return;
}
else
{
if (e.Column.FieldName == "Description")
{
if (e.CellValue == null || string.IsNullOrWhiteSpace(e.CellValue.ToString()))
{
AppearanceHelper.Apply(e.Appearance, appError);
//ErrorInvoice = true;
}
}
if (e.Column.FieldName == "Quantity")
{
if (e.CellValue == null || e.CellValue.ToString() == "0")
{
AppearanceHelper.Apply(e.Appearance, appError);
//ErrorInvoice = true;
}
}
if (e.Column.FieldName == "Price")
{
if (e.CellValue == null || e.CellValue.ToString() == "0")
{
AppearanceHelper.Apply(e.Appearance, appError);
}
}
if (e.Column.FieldName == "Amount")
{
if (e.CellValue == null || e.CellValue.ToString() == "0")
{
AppearanceHelper.Apply(e.Appearance, appError);
}
}
}
}
单元格控件赋值
#region 发票明细数据
//原产地
gltxtCountryOrigin.DataSource = cname;//原产地二字码
this.gltxtCountryOrigin.NullText = "";
this.gltxtCountryOrigin.DisplayMember = "Col001";
this.gltxtCountryOrigin.ValueMember = "Col001";
this.gltxtCountryOrigin.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
this.gltxtCountryOrigin.View.BestFitColumns();
this.gltxtCountryOrigin.ShowFooter = false;
this.gltxtCountryOrigin.View.OptionsView.ShowAutoFilterRow = true; //显示不显示grid上第一个空行,也是用于检索的应用
//this.cmb_rCountryCode.Properties.AutoComplete = false;
this.gltxtCountryOrigin.ImmediatePopup = true;////在输入框按任一可见字符键时立即弹出下拉窗体
this.gltxtCountryOrigin.PopupFilterMode = DevExpress.XtraEditors.PopupFilterMode.Contains;//
this.gltxtCountryOrigin.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
//数量单位
var mienu_QuantityUnits = quantityUnitsBLL.GetQuantityUnitsList().OrderBy(o => o.quCode).ToList();//数量单位
this.gltxtNumberUnits.DataSource = mienu_QuantityUnits;
this.gltxtNumberUnits.NullText = "";
this.gltxtNumberUnits.DisplayMember = "quCode";
this.gltxtNumberUnits.ValueMember = "quCode";
this.gltxtNumberUnits.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
this.gltxtNumberUnits.View.BestFitColumns();
this.gltxtNumberUnits.ShowFooter = false;
this.gltxtNumberUnits.View.OptionsView.ShowAutoFilterRow = true; //显示不显示grid上第一个空行,也是用于检索的应用
//this.gltxtNumberUnits.Properties.AutoComplete = false;
this.gltxtNumberUnits.ImmediatePopup = true;////在输入框按任一可见字符键时立即弹出下拉窗体
this.gltxtNumberUnits.PopupFilterMode = DevExpress.XtraEditors.PopupFilterMode.Contains;//
this.gltxtNumberUnits.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
#endregion
单元格属性设置
gridview单元格编辑添加数据的更多相关文章
- MFC List Control 控件添加单元格编辑,实现可编辑重写
在实现随机生成四则运算的个人项目中,目前已经完成基本功能,想要把程序变成一个Windows界面的程序.原本以为学习过MFC,应该很快就能完成.但是由于以前用的都是VC6.0,这次用了VS2010,稍微 ...
- Bootstrap:Bootstrap_table第一篇:快速用bootstrap_table(支持参数)筛选并展示数据,固定表格前几列,实现表格单元格编辑
1.准备好css和js文件 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstr ...
- jqGrid单元格编辑配置,事件及方法
转自 http://blog.csdn.net/xueshijun666/article/details/18151055 // var ret = $("#in_store_list_de ...
- GridControl单元格编辑验证的方法
本文实例演示了DevExpress实现GridControl单元格编辑验证的方法,比较实用的功能,具体方法如下: 主要功能代码如下: /// <summary> /// 自定义单元格验证 ...
- JQgrid实现全表单元格编辑
1 jQuery("#baseWageDataValueGrid").jqGrid('setGridParam',{'cellEdit':true}); 2 3 //修改所有td ...
- Dev控件GridView单元格绑定控件
Dev控件GridView单元格绑定控件 //文本按钮 RepositoryItemButtonEdit btnFields = new RepositoryItemButtonEdit();//创建 ...
- sencha gridpanel 单元格编辑
{ xtype: 'gridpanel', region: 'north', height: 150, title: 'My Grid Panel', store: 'A_Test_Store', c ...
- Datagrid扩展方法InitEditGrid{支持单元格编辑}
//-----------------------------------------------------------------/******************************** ...
- Datagrid扩展方法onClickCell{easyui-datagrid-扩充-支持单元格编辑}
//-----------------------------------------------------------------/******************************** ...
随机推荐
- 邻居子系统 之 状态定时器回调neigh_timer_handler
概述 在分配邻居子系统之后,会设置定时器来处理那些需要定时器处理的状态,定时器回调函数为neigh_timer_handler:函数会根据状态机变换规则对状态进行切换,切换状态后,如果需要更新输出函数 ...
- Nginx之编写HTTP模块
1. 常用数据结构 1.1 ngx_str_t typedef struct { /* * 字符串的有效长度 */ size_t len; /* * 有效字符串的起始地址,该字符串通常并不以'\0'结 ...
- QTcpSocket 发送数据的几种方法
1.QTcpSocket 继承于QAbstractSocket继承于QIODevice 2.QTcpSocket 提供的几种接收和发送数据方法 write ( const char *, qint64 ...
- postman设置环境变量,实现一套接口根据选择的环境去请求不同的url
一个系统,有本地,开发,测试,生产等不同的环境,如果写不同的url配置多套会比较麻烦,可以设置不同的环境实现不同的url之间的切换.配置之后如下: 第一步: 第二步: 添加环境变量 ps::不同的环境 ...
- 软件-绘图-AutoCAD:百科
ylbtech-软件-绘图-AutoCAD:百科 AutoCAD(Autodesk Computer Aided Design)是Autodesk(欧特克)公司首次于1982年开发的自动计算机辅助设计 ...
- 【Taro全实践】6位验证码输入视觉分离(标准下划线分离)
一.实现的效果图 二.实现思路 中间想过很多实现方法,但是因为input为原生组件的原因,很难适配所有手机直接. 所有如何实现适配所有手机的验证码分离输入呢?(思路如下) 1.input组件为原生组件 ...
- 在业务控制方法中写入User,Admin多个模型收集参数
1) 可以在业务控制方法中书写1个模型来收集客户端的参数 2) 模型中的属性名必须和客户端参数名一一对应 3) 这里说的模型不是Model对象,Model是向视图中封装的数据 @Controll ...
- TelephonyUtils
<uses-permission android:name="android.permission.CALL_PHONE"/> import java.util.Arr ...
- 部署Hadoop-3.0-高性能集群
一.Hadoop概述: Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop的框 ...
- es6 实现双链表
const util = require('util'); /** * 链表节点类 */ class Node { constructor (ele) { this.ele = ele; this.n ...