在DGV中有一列是折扣的,现在要实现的功能就是,但你在折扣这列中的单元格里输入一个数字,比如2时
当光标离开这个单元格时,此单元格变自动显示为0.2。就是除10。

解决方案 »

  1.   

    如果是我 我就会去找这个DGV的事件 ,里面肯定有关于离开焦点,或者说cell编辑完成的事件
      

  2.   

    写个事件函数吧,在里面把值改成你要的格式就可以了this.DataGridView.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.DataGridViewPowerSensor_CellFormatting);
      

  3.   

    //当光标离开单元格时触发
    private void dgvFileDataInfo_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                   //string strColumnName = dgvFileDataInfo.Columns[e.ColumnIndex].Name; //获取点击的列名
                     //判断列
                     if("折扣列")
                   {
                        //先获取输入的值
                           //再把折扣列单元格的值/10之后再赋给折扣列的单元格
                           //比如
                           string strText = Convert.ToString(this.dgv.Rows[].Cells[].Value);
                        //根据你的数据类型需要转化成相应的数据类型
                           int intNum = int.Parse(strText);
                        this.dgv.Rows[].Cells[].Value = intNum /10;
                   }
            }大致代码是这样,具体的根据你自己的需要!!!
      

  4.   

    使用时也可以参考参考dgvFileDataInfo_CellValueChanged这个事件,单元格的值发生改变时触发的事件!
      

  5.   

    你所用的事件操作的对象应该是cell,不应该是row
      

  6.   

    是CELL 我用的是dataGridView1_CellEndEdit(
      

  7.   

    你要在事件里用e.ColumnIndex先判断一下事件发生的列
      

  8.   

    直接用事件撒...
    选择DGV 属性--事件--CellEndEdit--双击进去以后
    定义当前行
    DataGridViewRow dr = this.DGV.CurrentRow;   //DGV为你的DataGridView
    if (e.ColumnIndex == 5)    //5为你折扣那列的列数,假设是5 
    {
        dr.Cells[5].Value = dr.Cells[5].Value /10;
    }
       其他的判断自己加吧