// <summary>
/// 改变行的颜色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgList_LoadingRow(object sender, DataGridRowEventArgs e)
{
//Color col = ColorTranslator.FromHtml(strColor);
if (e.Row.GetIndex() == 1)
{
SolidColorBrush brush = new SolidColorBrush(ToColor.HtmlToColor("#e2ecf3"));
e.Row.Background = brush;
}
else
{
if (e.Row.GetIndex() != 1)
{
if (e.Row.GetIndex() / 2 > 0)
{
SolidColorBrush brush = new SolidColorBrush(ToColor.HtmlToColor("#e2ecf3"));
e.Row.Background = brush;
}
}
}
//DataGridViewRow dgr = dataGridView1.Rows[e.Row.GetIndex()];
//try
//{
// if (dgr.Cells["列名 "].Value.ToString() == "比较值 ")
// {
// dgr.DefaultCellStyle.ForeColor = 设置的颜色;
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
public static Color HtmlToColor(string htmlColr)
{int baseIndex = 1;
byte a, r, g, b;
a = r = g = b = 255;
if (htmlColr.Length == 9)
{
a = Convert.ToByte(htmlColr.Substring(baseIndex, 2), 16);
baseIndex += 2;
}
r = Convert.ToByte(htmlColr.Substring(baseIndex, 2), 16);
g = Convert.ToByte(htmlColr.Substring(baseIndex += 2, 2), 16);
b = Convert.ToByte(htmlColr.Substring(baseIndex += 2, 2), 16);
return Color.FromArgb(a, r, g, b);
}