在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 ="入库倒冲";
}
}
}
}
[最优解释]
/// <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
{}
}
}
}
[其他解释]
dataGridView1.Rows[i].Cells[11].Value = "领用";
这里要求填写byte类型的值,你写的字符串
[其他解释]
可以把“领用”定义为枚举项,并赋值为3
,其余的类似
[其他解释]
你这列dataGridView1.Rows[i].Cells[11].Value 绑定的byte类型的?
[其他解释]
你数据库里面或者数据源中“领用”这个字段的类型是 字节byte(当字节值为3的时候,你绑定了) ,应该定义数据源中(就是那个“3”为字符串型就可以了)为字符串型,才可以。
[其他解释]