2 zllxp1314 zllxp1314 于 2016.03.03 10:38 提问

根据DataGridView某列的某个值,我写了一个函数来设置行背景色,但效果错

//窗体加载事件
private void frmOrderManagement_Load(object sender, EventArgs e)
{
if (GlobalHelper._order == 0)//订单下单
{
tsbtnPlaceOreder.Visible = false;
tsbtnFinanceSure.Visible = false;
LoadOrder();
}
else if (GlobalHelper._order == 1)//财务审核
{
tsbtnAddOrder.Visible = false;
tsbtnDelete.Visible = false;
tsbtnUpdateOrder.Visible = false;
tsbtnRearchOrder.Visible = false;
tsbtnLoadOrder.Visible = false;
tsbtnLeadingOut.Visible = false;
tsbtnPlaceOreder.Visible = false;
LoadUnCheckOrder();
}
else if (GlobalHelper._order == 2)//订单下发
{
tsbtnAddOrder.Visible = false;
tsbtnDelete.Visible = false;
tsbtnUpdateOrder.Visible = false;
tsbtnRearchOrder.Visible = false;
tsbtnLoadOrder.Visible = false;
tsbtnLeadingOut.Visible = false;
tsbtnFinanceSure.Visible = false;
LoadCheckedOrder();
}
}
//双击事件
private void dgViewXOrderInfo_DoubleClick_1(object sender, EventArgs e)
{
SetDgvBackColor();
if (GlobalHelper._order == 0)//订单下单
{
return;
}
else if (GlobalHelper._order == 1)//财务审核
{
GlobalHelper._upOrAdd = 101;
frmOrderAddOrupdate frmOrderUpdate = new frmOrderAddOrupdate(LoadOrder, UpdateInfo);
frmOrderUpdate.ShowDialog();
LoadUnCheckOrder();
SetDgvBackColor();
}
else if (GlobalHelper._order == 2)//订单下发
{
if (arrangeUser == "")
{
DialogResult re = MessageBox.Show("确定下发订单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
if (re == DialogResult.OK)
{
int r = bll.DeliveryOrder(orderCode, GlobalHelper._uName, DateTime.Now);
if (r > 0)
{
LoadCheckedOrder();
SetDgvBackColor();
}
}
else
{
return;
}
}
else
{
DialogResult re = MessageBox.Show("该订单已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
public void SetDgvBackColor()
{
foreach (DataGridViewRow row in dgViewXOrderInfo.Rows)
{
string RowType = row.Cells[14].Value.ToString();
string RowType1 = row.Cells[20].Value.ToString();
if (RowType == "未审核")
{
row.DefaultCellStyle.BackColor = Color.LightPink;
}
else if (RowType == "审核通过")
{
row.DefaultCellStyle.BackColor = Color.LightBlue;
}
if (RowType1 != "")
{
row.DefaultCellStyle.BackColor = Color.LightGreen;
}
}
}

 在窗体加载函数(Load函数)里完全没有效果,但是在行双击事件里有效果,这是设置背景设函数,不知道哪儿出错了

1个回答

caozhy
caozhy   Ds   Rxr 2016.03.07 05:27
Csdn user default icon
上传中...
上传图片
插入图片