private void dgvPapildSummas_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { if (e.ColumnIndex == dgcPSIDNO.Index) { if (e.RowIndex == dgvPapildSummas.NewRowIndex) { e.Cancel = true; return; } var cell = dgvPapildSummas[e.ColumnIndex, e.RowIndex] as DataGridViewComboBoxCell; var drv = dgvPapildSummas.Rows[e.RowIndex].DataBoundItem as DataRowView; var dr = drv.Row as KlonsADataSet.POSITIONS_PLUSMINUSRow; if (dr.IsIDSVNull()) { e.Cancel = true; return; } var allowed = SomeDataDefs.GetAllowedEBonusFrom(dr.XBonusType); if (allowed.Length == 0) { e.Cancel = true; return; } var list = SomeDataDefs.GetBonusFromItems(allowed); cell.DataSource = list; cell.DisplayMember = "Val"; cell.ValueMember = "Key"; } }
private void POSITIONS_PLUSMINUS_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (e.Column == MyData.DataSetKlons.POSITIONS_PLUSMINUS.IDSVColumn) { var dr = e.Row as KlonsADataSet.POSITIONS_PLUSMINUSRow; if (e.ProposedValue == null || e.ProposedValue == DBNull.Value) { if (dr.IsIDNONull()) { return; } dr["IDNO"] = DBNull.Value; dr.EndEdit(); return; } var bonustype = (EBonusType)e.ProposedValue; var allowed = SomeDataDefs.GetAllowedEBonusFrom(bonustype); var list = SomeDataDefs.GetBonusFromItems(allowed); if (list == null || list.Length == 0) { dr["IDNO"] = DBNull.Value; dr.EndEdit(); return; } if (dr.XBonusFrom == EBonusFrom.None || !allowed.Contains(dr.XBonusFrom)) { dr.XBonusFrom = allowed[0]; dr.EndEdit(); return; } } }