if (dataGridViewForUser.RowCount > 0)
{
DataGridViewTextBoxCell txtcell = new DataGridViewTextBoxCell();
for (int i = 0; i < dataGridViewForUser.Rows.Count; i++)
{
int position = int.Parse(ds.Tables[0].Rows[i]["校区"].ToString());
//this.dataGridViewForUser.Rows[i].Cells[2].ValueType = typeof(String);
this.dataGridViewForUser.Rows[i].Cells[2] = txtcell;
switch (position)
{
case 1: this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
case 2:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
case 3:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
default:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "其他";
break;
}
}
}
我想要把对应的校区代码,换为对应的文字,但现实提示“***校区”是不是int32,我不是已经修改了单元格的属性么,大侠帮忙看下
{
DataGridViewTextBoxCell txtcell = new DataGridViewTextBoxCell();
for (int i = 0; i < dataGridViewForUser.Rows.Count; i++)
{
int position = int.Parse(ds.Tables[0].Rows[i]["校区"].ToString());
//this.dataGridViewForUser.Rows[i].Cells[2].ValueType = typeof(String);
this.dataGridViewForUser.Rows[i].Cells[2] = txtcell;
switch (position)
{
case 1: this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
case 2:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
case 3:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "***校区";
break;
default:
this.dataGridViewForUser.Rows[i].Cells[2].Value = "其他";
break;
}
}
}
我想要把对应的校区代码,换为对应的文字,但现实提示“***校区”是不是int32,我不是已经修改了单元格的属性么,大侠帮忙看下
dgv.CellFormatting += (s, e) =>
{
if (e.ColumnIndex > -1 && e.RowIndex > -1)
{
int position;
if (int.TryParse(dgv.Rows[e.RowIndex].Cells["校区"].Value.ToString(), out position))
{
switch (position)
{
case 1:
e.Value = "***校区";
break;
case 2:
e.Value = "***校区";
break;
case 3:
e.Value = "***校区";
break;
default:
e.Value = "其他";
break;
}
}
}
};