private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (this.dataGridView1.CurrentCell.ColumnIndex == this.DataType.Index) { //limit this dropdown to just the valid data types for this measure BindingSource bindingSource = this.dataGridView1.DataSource as BindingSource; MeasureGroupHealthCheckPlugin.MeasureHealthCheckResult item = bindingSource.Current as MeasureGroupHealthCheckPlugin.MeasureHealthCheckResult; DataGridViewComboBoxEditingControl comboBox = e.Control as DataGridViewComboBoxEditingControl; comboBox.DataSource = item.PossibleDataTypes; comboBox.SelectedValue = item.DataType; //not necessary to capture this event and commit a change before they leave the cell because we decided not to change cell colors or anything //comboBox.SelectionChangeCommitted -= this.comboBox_SelectionChangeCommitted; //comboBox.SelectionChangeCommitted += this.comboBox_SelectionChangeCommitted; } }
private void FormatGrid() { //this doesn't work... ends up middle aligning the col headers I wanted right aligned... bug in DataGridView maybe //foreach (DataGridViewColumn col in this.dataGridView1.Columns) //{ // col.HeaderCell.Style.Alignment = col.DefaultCellStyle.Alignment; //} foreach (DataGridViewRow row in this.dataGridView1.Rows) { MeasureGroupHealthCheckPlugin.MeasureHealthCheckResult item = (MeasureGroupHealthCheckPlugin.MeasureHealthCheckResult)row.DataBoundItem; if (item.CurrentDataType != item.DataType) { Color newColor = Color.Blue; if (item.CurrentDataType.max < item.DataType.max) { newColor = Color.Red; } foreach (DataGridViewCell cell in row.Cells) { cell.Style.ForeColor = newColor; } } } }