动态添加DataGridView Row Color

来源:互联网 发布:犀牛软件 手机 编辑:程序博客网 时间:2024/05/16 06:35
 private delegate void SetDataGridDataRowColor(DataGridView dv, int row, Color c);        private void SetdataGridRowColor(DataGridView dv, int row, Color c)        {            if (dv.InvokeRequired)            {                dv.Invoke(new SetDataGridDataRowColor(SetdataGridRowColor), dv, row, c);            }            else            {                dv.Rows[row].DefaultCellStyle.BackColor = c;            }        }        private delegate void SetDataGridDataRow(DataGridView dv, int row, string strLine);        private void SetdataGridRow(DataGridView dv, int row, string strLine)        {            if (dv.InvokeRequired)            {                dv.Invoke(new SetDataGridDataRow(SetdataGridRow), dv, row, strLine);            }            else            {                int status = 0;                bool superAnonymous = false;                int id = int.Parse(dv.Rows[row].Cells["P_ID"].Value.ToString());                if (strLine.Contains(@"验证失败"))                {                    dv.Rows[row].Cells["Status"].Value = 0;                    status = 0;                    dv.Rows[row].Cells["SuperAnonymous"].Value = false;                    dv.Rows[row].DefaultCellStyle.ForeColor = Color.DarkGray;                }                else                {                    dv.Rows[row].Cells["Status"].Value = 1;                    status = 1;                    dv.Rows[row].Cells["SuperAnonymous"].Value = false;                    dv.Rows[row].DefaultCellStyle.ForeColor = Color.DarkOrange;                }                new DBOperator().ModifyProxy(id, status, superAnonymous);                SetdataGridRowColor(ProxydataGridView, row, ProxydataGridView.DefaultCellStyle.BackColor);            }        }        private delegate void SetDataGridDataRowSource(DataGridView dv, DataTable table);        private void SetdataGridRowSource(DataGridView dv, DataTable table)        {            if (dv.InvokeRequired)            {                dv.Invoke(new SetDataGridDataRowSource(SetdataGridRowSource), dv, table);            }            else            {                dv.DataSource = table;            }        }

0 0