//컬럼초기화
this.dataGridView1.Columns.Clear();
//컬럼 명 변경
this.dataGridView1.Columns.Add("gubun", "구분");
this.dataGridView1.Columns.Add("monthly", month);
//컬럼 숨기기
this.dataGridView1.Columns.Add("devi_name", "비고");
this.dataGridView1.Columns["devi_name"].Visible = false;
//컬럼 고정
this.dataGridView1.Columns[5].Frozen = true;
this.dataGridView1.Columns[5].DividerWidth = 2;
//컬럼 싸이즈
this.dataGridView1.Columns[0].Width = 170;
this.dataGridView1.Columns[1].Width = 90;
//컬럼 색상
this.dataGridView1.Columns[13].DefaultCellStyle.BackColor = Color.Cornsilk;
//Sort 금지
int i;
for (i = 0; i <= 19; i++)
{
this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
// DB Binding 컬럼 지정
foreach (DataRow r in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = r["devi_cd"].ToString();
dataGridView1.Rows[n].Cells[1].Value = r["devi_name"].ToString();
dataGridView1.Rows[n].Cells[2].Value = r["gubun"].ToString();
}
// DB Binding DataTable
DataTable dt = db.GetDBTable(sql);
dataGridView1.DataSource = dt;
dataGridView1.Columns[3].Frozen = true;
dataGridView1.Columns[3].DividerWidth = 2;
// Datagridview Row 색상 변경
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//TOTAL
if (dataGridView1.Rows[e.RowIndex].Cells["devi_name"].Value.ToString() ==
"A" && dataGridView1.Rows[e.RowIndex+3].Cells["gubun"].Value.ToString() == "LIPAS")
{
dataGridView1.Rows[e.RowIndex+3].DefaultCellStyle.BackColor = Color.FromArgb(255, 196, 255);
}
if (dataGridView1.Rows[e.RowIndex].Cells["devi_name"].Value.ToString() == "A"
&& dataGridView1.Rows[e.RowIndex+4].Cells["gubun"].Value.ToString() == "VOLPAS")
{
// 전체 폰트
dataGridView1.Rows[e.RowIndex+4].DefaultCellStyle.BackColor = Color.FromArgb(255, 232, 255);
}
} |
//컬럼초기화
this.dataGridView1.Columns.Clear();
//컬럼 명 변경
this.dataGridView1.Columns.Add("gubun", "구분");
this.dataGridView1.Columns.Add("monthly", month);
//컬럼 숨기기
this.dataGridView1.Columns.Add("devi_name", "비고");
this.dataGridView1.Columns["devi_name"].Visible = false;
//컬럼 고정
this.dataGridView1.Columns[5].Frozen = true;
this.dataGridView1.Columns[5].DividerWidth = 2;
//컬럼 싸이즈
this.dataGridView1.Columns[0].Width = 170;
this.dataGridView1.Columns[1].Width = 90;
//컬럼 색상
this.dataGridView1.Columns[13].DefaultCellStyle.BackColor = Color.Cornsilk;
//Sort 금지
int i;
for (i = 0; i <= 19; i++)
{
this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
// DB Binding 컬럼 지정
foreach (DataRow r in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = r["devi_cd"].ToString();
dataGridView1.Rows[n].Cells[1].Value = r["devi_name"].ToString();
dataGridView1.Rows[n].Cells[2].Value = r["gubun"].ToString();
}
// DB Binding DataTable
DataTable dt = db.GetDBTable(sql);
dataGridView1.DataSource = dt;
dataGridView1.Columns[3].Frozen = true;
dataGridView1.Columns[3].DividerWidth = 2;
// Datagridview Row 색상 변경
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//TOTAL
if (dataGridView1.Rows[e.RowIndex].Cells["devi_name"].Value.ToString() ==
"A" && dataGridView1.Rows[e.RowIndex+3].Cells["gubun"].Value.ToString() == "LIPAS")
{
dataGridView1.Rows[e.RowIndex+3].DefaultCellStyle.BackColor = Color.FromArgb(255, 196, 255);
}
if (dataGridView1.Rows[e.RowIndex].Cells["devi_name"].Value.ToString() == "A"
&& dataGridView1.Rows[e.RowIndex+4].Cells["gubun"].Value.ToString() == "VOLPAS")
{
// 전체 폰트
dataGridView1.Rows[e.RowIndex+4].DefaultCellStyle.BackColor = Color.FromArgb(255, 232, 255);
}
}