编辑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 参考: ...
随机推荐
- jQuery为div添加select和option
简单描述:用jQuery给页面添加select下拉框,直接上图 总结:清楚明了^_^
- ubuntu MySQL的安装
https://i.cnblogs.com/EditPosts.aspx?opt=1 https://juejin.im/entry/5adb5deff265da0b9d77cb3b MySQL Co ...
- windows 7 下用git
参考:http://my.oschina.net/longxuu/blog/141699
- 常见的爬虫分析库(1)-Python3中Urllib库基本使用
原文来自:https://www.cnblogs.com/0bug/p/8893677.html 什么是Urllib? Python内置的HTTP请求库 urllib.request ...
- 让Mysql支持Emoji表情,解决[Err] 1366 - Incorrect string value: '\xF0\xA3\x84\x83'
mysql insert内容包含表情或者unicode码时候,插入Mysql时失败了,报如下异常: java.sql.SQLException: Incorrect string value: '\x ...
- 16位和32位的80X86汇编语言的区别
需要注意的是汇编不是一种语言,不同平台有不同的汇编语言对应,因为汇编和操作系统平台相关,所以汇编语言没有移植性.对于IA-32架构平台而言,选用的32位80386汇编语言,也就只说讨论的操作系统平台是 ...
- elasticsearch-HQ 安装与使用
https://github.com/ElasticHQ/elasticsearch-HQ Download or clone the repository. Open terminal and po ...
- delphi TreeView 从数据库添加节点的四种方法
方法一:delphi中递归算法构建treeView 过程:通过读取数据库中table1的数据,来构建一颗树.table1有两个字段:ID,preID,即当前结点标志和父结点标志.所以整个树的表示为父母 ...
- 剑指offer错题记录
错误重点: 1. 传递vector参数时,如果调用函数改变了vector的内容,一定一定要&,传引用保持一致 旋转数组的最小数字:有重复数字情况,二分查找照样搞.情况考虑要周全,当a[mid] ...
- 关于tornado中session的总结
#!/usr/bin/env python# _*_ coding:utf-8 _*_ import tornado.webimport tornado.ioloop container = {} # ...