我可以在以下问题上使用一些帮助:
我每个月的每一天都有 31 个面板。每当那天(在数据集中)找到记录时,我想更改面板的背景。
如果您查看代码,您可以看到我要去哪里,所有面板都需要单独指出。如果你问我,这看起来很长。我认为您需要为所有面板建立索引?
有另一种/更好的方法吗?如果是这样,怎么办?
int MaxRows;
MaxRows = ds.Tables["Dataset"].Rows.Count;
for (int i = 0; i != (MaxRows); i++)
{
DataRow dRow = ds.Tables["Dataset"].Rows[i];
if (dRow.ItemArray.GetValue(1).ToString() == "1")
{
panDay1.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "2")
{
panDay2.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "3")
{
panDay3.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "4")
{
panDay4.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "5")
{
panDay5.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "6")
{
panDay6.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "7")
{
panDay7.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "8")
{
panDay8.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "9")
{
panDay9.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "10")
{
panDay10.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "11")
{
panDay11.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "12")
{
panDay12.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "13")
{
panDay13.BackColor = Color.LightSteelBlue;
}
else if (dRow.ItemArray.GetValue(1).ToString() == "14")
{
panDay14.BackColor = Color.LightSteelBlue;
}
etc.
etc.
etc.
谁能帮帮我?