//Format "Tarih" Column, set visible to true, color the odd and even lines, and allign some of the rows private void DataGridViewFormat(DataTable dt) { if (dt == null) { return; } //we probably got an exception from query. Do nothing. DataTableExt.ConvertColumnType(dt, "Tarih"); dataGridView1.DataSource = new BindingSource(dt, null); dataGridView1.Visible = true; DataGridLineColoring(); DataGridLineAlignment(); }
//Format "Tarih" Column, set visible to true, color the odd and even lines, and allign some of the rows private void DataGridViewFormat(DataTable dt, int latestVadeRow, int vade) { DataTableExt.ConvertColumnType(dt, "Tarih"); dataGridView1.DataSource = new BindingSource(dt, null); dataGridView1.EvenRowColoring(Color.WhiteSmoke); if (vade > 0) { foreach (DataGridViewRow row in dataGridView1.Rows) { DateTime vadeDateTime = (DateTime)row.Cells[0].Value; double difference = (DateTime.Today - vadeDateTime).TotalDays; if (vadeStartRow != -1 && vadeFinishRow != -1 && row.Index <= vadeFinishRow && row.Index >= vadeStartRow) { if (row.Index % 2 == 0) { row.DefaultCellStyle.BackColor = Color.FromArgb(255, 140, 140); } else { row.DefaultCellStyle.BackColor = Color.FromArgb(255, 115, 115); } continue; } if (row.Index >= latestVadeRow) { if (row.Index % 2 == 0) { row.DefaultCellStyle.BackColor = Color.FromArgb(230, 229, 238); } else { row.DefaultCellStyle.BackColor = Color.FromArgb(216, 229, 228); } } } vadeStartRow = -1; vadeFinishRow = -1; } DataGridLineAlignment(); dataGridView1.SetColumnSortMode(DataGridViewColumnSortMode.NotSortable); }