private void datagridview1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[11].Value != null && dataGridView1.Rows[i].Cells[11].ColumnIndex == 11)
                {
                    dataGridView1.Rows[i].Cells[11].Tag = dataGridView1.Rows[i].Cells[11].Value.ToString();
                    if (dataGridView1.Rows[i].Cells[11].Value.ToString() == "3")
                    {
                        dataGridView1.Rows[i].Cells[11].Value = "领用";
                    }
                    else if (dataGridView1.Rows[i].Cells[11].Value.ToString() == "4")
                    {
                        dataGridView1.Rows[i].Cells[11].Value = "虚拟件";
                    }
                    else if (dataGridView1.Rows[i].Cells[11].Value.ToString() == "1")
                    {
                        dataGridView1.Rows[i].Cells[11].Value ="入库倒冲";
                    }
                }
            }
        }

解决方案 »

  1.   

    dataGridView1.Rows[i].Cells[11].Value = "领用";这里要求填写byte类型的值,你写的字符串
      

  2.   

    你这列dataGridView1.Rows[i].Cells[11].Value 绑定的byte类型的?
      

  3.   

    你数据库里面或者数据源中“领用”这个字段的类型是 字节byte(当字节值为3的时候,你绑定了) ,应该定义数据源中(就是那个“3”为字符串型就可以了)为字符串型,才可以。
      

  4.   

    可是dataGridView1.Rows[i].Cells[11].Value会直接将"领用"传入数据库,其实我想要的是‘3’的值而不是"领用"有什么方法解决么?高手
      

  5.   

    是数据库里是tinyint型。在C#中就会是byte类型
      

  6.   


    知道你想要干什么了,,有2中方法:
    第一中:你显示的时候可以再数据库中修改后直接显示在界面就可以了
    用 Case When Zhen 将数字改成你想要的,
    第二种用DataGridView的CellFormating事件        /// <summary>
            /// datagridview数据格式化,
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void DgvOverTime_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.ColumnIndex == 11)
                {
                    DataGridViewRow row = this.DgvOverTime.Rows[e.RowIndex];
                    if (row != null)
                    {
                        if (row.Cells["finishDates"].Value.ToString() != null && row.Cells["finishDates"].Value.ToString() != "3")
                        {
                            e.Value = "领用";
                        }
                        else if()
                        { }
                        else
                        {}
                    }
                }
            }