以这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单元格的更多相关文章

  1. WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序

    TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...

  2. DataGridView单元格内容自动匹配下拉显示

    页面显示数据使用的控件是ComponentFactory.Krypton.Toolkit中的KryptonDataGridView控件.在指定“商品”单元格中需要根据用户输入内容自动匹配数据库中商品信 ...

  3. DataGridView 单元格自动填充

    在DataGridView单元格中,当输入指定字符时,自动完成填充. 通过 TextBox实现 AutoCompleteMode AutoCompleteMode.Suggest: AutoCompl ...

  4. winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难

    // winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...

  5. Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值

    Delphi Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值 cxGrid1DBTableView1.Controller.FocusedRowIndex 当前行号 cxGrid1DB ...

  6. DataGridView单元格合并

    本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...

  7. DataGridView单元格显示GIF图片

    本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...

  8. Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)

    设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);

  9. Winform Datagridview 单元格html格式化支持富文本

    Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...

随机推荐

  1. C语言访问一个链接

    示例代码1: # include <Windows.h> int main(){ system("start http://""www.baidu.com&q ...

  2. C++ 关于ShowWindow()的疑问

    IDE: Code::Blocks 16.01 操作系统:Windows 7 x64 最初的代码,目的是为了隐藏窗口出现在任务栏上的图标. #include <windows.h> usi ...

  3. 把tomcat服务器配置为windows服务的方法

    转自:http://ykyfendou.iteye.com/blog/2032916 使用tomcat开发的项目,我们把项目交付给客户的时候,客户都不希望在每次开机的时候都要启动一下tomcat服务器 ...

  4. AI-解析器-request.data内部如何按照自定义解析格式-解析数据

    QUESTION:post方法中调用request.data方法时,当在Courseview类中添加parser_classes=[ForParser,],就可以将数据解析成parser_classe ...

  5. C++ Primer 笔记——数组

    1.数组的大小是固定不变的,声明时必须指定大小(或者使用列表初始化),而且大小必须大于0,C++ Primer里面也建议,如果不确定元素的个数,请使用vector. ]; , , }; //数组长度固 ...

  6. NPOI操作Excel(一)--NPOI基础

    用C#读取Excel的方法有很多中,由于近期工作需要,需要解析的Excel含有合并单元格以及背景色等特殊要求,故在网上查了一些关于读Excel的方法的优缺点,觉得NPOI能满足我的需要,所以搜索了一些 ...

  7. 提取Word里的文本内容 C#

    using DocumentFormat.OpenXml.Packaging; public static string TextFromWord(string path) { const strin ...

  8. python网络爬虫day1

    python爬虫真的很方便,自己不能忽视的问题就是字符编码的问题,一直想腾出时间来看,一直没有时间.明天开始看吧. 今天是学习python爬虫的第一天,从B站上搜到的,可惜可惜. import req ...

  9. 如何设置Navicat的显示字体与字体大小?

    方法/步骤     打开Navicat   点击[工具]菜单,再选择[选项]   在[选项]界面,点击[外观]下的[字体]   设置网格字体和大小   设置编辑器字体和大小   设置命令列界面字体和大 ...

  10. MVC Filter

    一.Filter在MVC生命周期中的位置 1.IIS中传递请求到程序2.MVC根据Routing来选择由哪个Controller/Action来处理3.Controller调用Model(业务逻辑)来 ...