private void AdjustComboBoxCellColor(PositiveHabitFrequency tempFrequency, DataGridViewComboBoxCell dgvComboBoxCell) { switch (tempFrequency) { case PositiveHabitFrequency.NOT_DOING: { dgvComboBoxCell.Style.BackColor = System.Drawing.Color.Crimson; break; } case PositiveHabitFrequency.TOO_LITTLE: { dgvComboBoxCell.Style.BackColor = System.Drawing.Color.Yellow; break; } case PositiveHabitFrequency.SATYSFYING: { dgvComboBoxCell.Style.BackColor = System.Drawing.Color.GreenYellow; break; } case PositiveHabitFrequency.ALWAYS: { dgvComboBoxCell.Style.BackColor = System.Drawing.Color.LawnGreen; break; } } }
//--------------------------------------------------------------------------- /// <summary> /// EH changing ComboBoxCell value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DgvPositiveHabits_CellValueChanged(object sender, DataGridViewCellEventArgs e) { // this EH fires as 2nd DataGridViewComboBoxCell dgvComboBoxCell = (DataGridViewComboBoxCell)dgvPositiveHabits.Rows[e.RowIndex].Cells[1]; if (dgvComboBoxCell != null) { try { PositiveHabitFrequency tempFrequency = (PositiveHabitFrequency)dgvComboBoxCell.Value; positiveHabitCollection[e.RowIndex].Frequency = tempFrequency; //one of enum value positiveHabitCollection[e.RowIndex].LastCheckedInComboBox = DateTime.Now.Date; //today's date dgvComboBoxCell.FlatStyle = FlatStyle.Popup; //changes ComboBox appearance dgvComboBoxCell.ReadOnly = true; //disables further modification AdjustComboBoxCellColor(tempFrequency, dgvComboBoxCell); UpdateMenuStripLabel(); } catch (System.ArgumentOutOfRangeException ex) { MessageBox.Show("don't tinker here !\n\n" + ex.ToString()); } } }