编辑datagridview单元格
以这3种为例,最简单的是第三种,直接让单元格处于可编辑状态,当完成编辑后触发CellEndEdit事件,最后对输入的数据进行处理。
private DateTimePicker dtp = new DateTimePicker();
private ComBox sellstyle = new ComBox ();//设置全局变量
public PlanVindicateForm()
{
InitializeComponent();
dgvReaschResult.Controls.Add(dtp);//在窗体的构造函数里将datetimepicker控件加入
this.dgvReaschResult.Controls.Add(this.sellstyle);//combox控件
this.sellstyle.Visible = false;//设置是否显示
this.dtp.Visible = false;
this.dtp.Format = DateTimePickerFormat.Custom;//设置显示格式
this.dtp.CustomFormat = "HH:mm";
this.dtp.KeyDown += new KeyEventHandler(dtp_KeyDown);//注册控件用到的事件
this.sellstyle.cbTypeBox.SelectedIndexChanged += new EventHandler(cbTypeBox_SelectedIndexChanged);
}
private void dgvReaschResult_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex > -) && (e.ColumnIndex > -))
{
string dataPropertyName = this.dgvReaschResult.Columns[e.ColumnIndex].DataPropertyName;
switch (dataPropertyName)
{
case "CanSellSeatCount": this.dgvReaschResult.BeginEdit(true);
this.Original = int.Parse(this.dgvReaschResult.Rows[this.dgvReaschResult.CurrentCell.RowIndex].Cells[e.ColumnIndex].Value.ToString());
return; case "DrvTime":
this.dgvReaschResult.BeginEdit(true);
this._Rectangle = this.dgvReaschResult.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
this.dtp.Size = new Size(this._Rectangle.Width, this._Rectangle.Height);
this.dtp.Location = new Point(this._Rectangle.X, this._Rectangle.Y);
this.dtp.Visible = true;
this.dtp.ShowUpDown = true;
this.dtp.Value = DateTime.Parse(this.SelectSchedule.DrvTime);
this.dtp.Focus();
this.originaTime = this.dtp.Value;
return; case "SellStyleName":
this.dgvReaschResult.BeginEdit(true);
this._Rectangle = this.dgvReaschResult.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
this.sellstyle.Size = new Size(this._Rectangle.Width, this._Rectangle.Height);
this.sellstyle.Location = new Point(this._Rectangle.X, this._Rectangle.Y);
this.sellstyle.Visible = true;
this.sellstyle.SelectedText = this.SelectSchedule.SellStyleName;
this.sellstyle.Focus();
this.sellStyleName = this.SelectSchedule.SellStyleName;
return;
}
this.dtp.Visible = false;
this.sellstyle.Visible = false;
} }
private void dgvReaschResult_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex > -) && (e.ColumnIndex > -))
{
try
{
string dataPropertyName = this.dgvReaschResult.Columns[e.ColumnIndex].DataPropertyName;//获取选中单元格的数据源的名称,即列名
int seats = ;
int num2 = ;
switch (dataPropertyName)
{
case "CanSellSeatCount";//第3种
{
//对获取到的数据进行处理
break;
}
case "DrvTime"://第1种
//对获取到的数据进行处理
break; case "SellStyleName"://第2种
//对获取到的数据进行处理
break; }
}
catch (Exception exception)
{
this.ShowError("执行失败!");
}
} }
编辑datagridview单元格的更多相关文章
- WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序
TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...
- DataGridView单元格内容自动匹配下拉显示
页面显示数据使用的控件是ComponentFactory.Krypton.Toolkit中的KryptonDataGridView控件.在指定“商品”单元格中需要根据用户输入内容自动匹配数据库中商品信 ...
- DataGridView 单元格自动填充
在DataGridView单元格中,当输入指定字符时,自动完成填充. 通过 TextBox实现 AutoCompleteMode AutoCompleteMode.Suggest: AutoCompl ...
- winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难
// winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...
- Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值
Delphi Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值 cxGrid1DBTableView1.Controller.FocusedRowIndex 当前行号 cxGrid1DB ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- DataGridView单元格显示GIF图片
本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...
- Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)
设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);
- Winform Datagridview 单元格html格式化支持富文本
Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...
随机推荐
- python(10): xlsxwriter模块
import xlsxwriter as writer 注意: xlsxwriter 只能创建新文件,不可以修改原有文件.如果创建新文件时与原有文件同名,则会覆盖原有文件. import xlsxwr ...
- django----Form详细信息
Form类: 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; Django内置字段 Field required=True, 是否允许为 ...
- Nginx详解二十八:Nginx架构篇Nginx+Lua的安全waf防火墙
Nginx+Lua的安全waf防火墙 看一下别人写好的:https://github.com/loveshell/ngx_lua_waf 先安装git:yum -y install git 在/opt ...
- Nginx详解二十三:Nginx深度学习篇之Nginx+Lua开发环境搭建
Nginx+Lua开发环境 1.下载LuaJIT解释器wget http://luajit.org/download/LuaJIT-2.0.2.tar.gztar -zxvf LuaJIT-2.0.2 ...
- OrCAD Capture CIS 16.6 修改原理图的页面大小
OrCAD Capture CIS 16.6 打开需要修改的原理图. 菜单:Options > Schematic Page Properties... 看图操作...
- C++ Primer 笔记——理解std::move
标准库move函数是使用右值引用的模板的一个很好的例子.标准库是这样定义std::move的: template <typename T> typename remove_referenc ...
- idea的操作
- 关于金蝶k3 wise供应生门户登陆界面屏蔽业务账套多余功能模块设置方法
关于金蝶k3 wise供应生门户登陆界面屏蔽业务账套多余功能模块设置方法 1. 找到以下路径 ...\Kingdee\K3ERP\KDHR\SITEFILE\WEBUI\ 找到“Login.aspx” ...
- 笔记本如何设置插入USB鼠标自动禁用触摸板
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Synaptics\SynTPEnh] [HKEY_LOCAL_MAC ...
- XShell发送命令到全部会话