日期:2014-05-17  浏览次数:20738 次

在gridview中加入combobox中这段代码老报错
 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 ="入库倒冲";
                    }
                }
            }
        }


------最佳解决方案--------------------
引用:
引用:你这列dataGridView1.Rows[i].Cells[11].Value 绑定的byte类型的?
是数据库里是tinyint型。在C#中就会是byte类型


知道你想要干什么了,,有2中方法:
第一中:你显示的时候可以再数据库中修改后直接显示在界面就可以了
用 Case When Zhen 将数字改成你想要的,
第二种用DataGridView的CellFormating事件

        /// <summary>
        /// datagridview数据格式化,
        /// </summary>