以这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. Linux基础实操二

    实操一: 1) 新建用户natasha uid为1000,gid为555,备注信息为“master” 2) 修改natasha用户的家目录为/Natasha 3) 查看用户信息配置文件的最后一行 ca ...

  2. cf219d 基础换根法

    /*树形dp换根法*/ #include<bits/stdc++.h> using namespace std; #define maxn 200005 ]; int root,n,s,t ...

  3. IP的计算

    IP的计算 时间限制: 1 Sec  内存限制: 32 MB 位无符号整数来表示,一般用点分方式来显示,点将IP地址分成4个部分,每个部分为8位,表示成一个无符号整数(因此不需要用正号出现),如192 ...

  4. C++ Primer 笔记——顺序容器

    1.标准库中定义了一些顺序容器,所有顺序容器都提供了快速顺序访问元素的能力. 2.如果容器的元素类型没有默认构造函数,那么在构造这个容器的时候不能只指定这个容器的数目,因为没有办法默认构造这些元素. ...

  5. ThreadLocal用法详解和原理

    一.用法 ThreadLocal用于保存某个线程共享变量:对于同一个static ThreadLocal,不同线程只能从中get,set,remove自己的变量,而不会影响其他线程的变量. 1.Thr ...

  6. docker批量删除none镜像

    1.直接用docker images | grep none | awk ‘{print $3}’ |xgars docker rmi 通过关键字搜索,得到docker id,进行删除

  7. 修改Linux服务器的ttl值

    [root@test_android_client_download ~]# cat /etc/sysctl.conf |grep net.ipv4.ip_default_ttlnet.ipv4.ip ...

  8. file按钮美化成图片(纯HTML+CSS)

    效果图: 代码实现: html: <div> <h2>上传头像</h2> <p class="fs18">(请上传200X200px ...

  9. models批量生成数据

    models批量生成数据 1.将数据生成为 列表序列,通过 bulk_create 将数据一次插入数据库中 def host(request): # 插入数据速度快消耗资源少 Hostlist=[] ...

  10. 使用android-ndk官方ndkbuild例子

    Why this blog 现在(2018年9月27日),Android Studio中新建ndk项目都使用cmake而不是Android.mk+Application.mk的方式.但老项目需要维护, ...