zoukankan      html  css  js  c++  java
  • DataGridView 在下拉框添加下来事件

    DataGridView中有一种下拉框式的列,给这个列添加下拉事件时需要转化一下才可以绑定下拉事件

    /// <summary>
    /// 服务类型
    /// </summary>
    DataGridViewComboBoxEditingControl cboServiceType = null;



    #region 维修项目 服务类型 下拉框 事件 /// <summary> /// 设置下拉框值改变时的处理 /// 作者“;李德彦 /// 时间:2015年12月7日 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgv_tb_maintain_three_guaranty_item_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { try { if (dgv_tb_maintain_three_guaranty_item.CurrentCell.OwningColumn == dgv_cbx1_WORK_SERVICE_TYPE) { cboServiceType = (DataGridViewComboBoxEditingControl)e.Control; cboServiceType.SelectedIndexChanged += new EventHandler(cboServiceType_SelectedIndexChanged); } } catch (Exception ex) { GlobalStaticObj.GlobalLogService.WriteLog(LocalOperation.GetStringByKey("sanbaofuwudantianjiamingxiyichang", "三包服务单,添加明细事件异常:") + ex.Message); } } /// <summary> /// 服务类型改变事件 /// 作者:李德彦 /// 时间:2015年12月7日 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void cboServiceType_SelectedIndexChanged(object sender, EventArgs e) { if (cboServiceType == null) { return; } if (cboServiceType.SelectedItem != null) { //当服务类型为“标准服务”时,行金额显示为具体数值,当服务类型为“宇通服务”和“其他服务”时,行金额显示0 DataRowView dr = (DataRowView)cboServiceType.SelectedItem; dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_cbx1_WORK_SERVICE_TYPE.Name].Value = dr["dic_name"]; dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_cbx1_WORK_SERVICE_TYPE.Name].Tag = dr["dic_code"]; if (dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_cbx1_WORK_SERVICE_TYPE.Name].Tag.ToString() == DbDic2Enum.OSN_SERVICE_TYPE_01)//标准服务 { //工时单价 string strfixed = string.Empty; if (dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_FIXED.Name].Value!=null && !string.IsNullOrEmpty(dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_FIXED.Name].Value.ToString())) { strfixed = dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_FIXED.Name].Value.ToString(); } string strtime = string.Empty; if (dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_TIME.Name].Value!= null && !string.IsNullOrEmpty(dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_TIME.Name].Value.ToString())) { //工时 strtime = dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_TIME.Name].Value.ToString(); } double doufixid, doutime,douretult = 0.00; if(double.TryParse(strfixed,out doufixid) && double.TryParse(strtime,out doutime)) { douretult = doufixid * doutime; } //行金额显示为具体数值 不需要保存两位小数,不需要四舍五入 dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_AMOUNT.Name].ReadOnly = true; dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_AMOUNT.Name].Value = douretult; } else { //行金额显示0 dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_AMOUNT.Name].Value = 0; dgv_tb_maintain_three_guaranty_item.CurrentRow.Cells[dgv_txt1_WORK_AMOUNT.Name].ReadOnly = true; } } } /// <summary> /// 结束编辑 /// 作者:李德彦 /// 时间:2015年12月7日 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgv_tb_maintain_three_guaranty_item_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { if (cboServiceType != null) { cboServiceType.SelectedValueChanged -= new EventHandler(cboServiceType_SelectedIndexChanged); cboServiceType = null; } } catch (Exception ex) { GlobalStaticObj.GlobalLogService.WriteLog(LocalOperation.GetStringByKey("sanbaofuwuzengjiachuangtidanyuangejieshuyichang", "三包服务增加窗体,单元格结束编辑事件异常:") + ex.Message); } } #endregion

      

  • 相关阅读:
    composer阿里云短信服务不支持传参为数值--为2017年短信接口,2018阿里云有更新http://www.cnblogs.com/q1104460935/p/8916096.html
    随机生成字符串,数字,手机号,邮箱
    C#: .net序列化及反序列化 [XmlElement(“节点名称”)] [XmlAttribute(“节点属性”)] (上篇)
    自动升级功能
    C# WinForm 设置按纽为透明,使用背景色
    sql server 2000 单主键高效分页存储过程 (支持多字段排序)
    分页存储过程
    C# WinForm 解决子窗体放大后,子窗体图标放大的问题
    Windows 7/8 64位系统 不能注册32位dll 文件的解决方案
    添加ico图标
  • 原文地址:https://www.cnblogs.com/yzhddeyan/p/5223184.html
Copyright © 2011-2022 走看看