protected virtual void PrepareVisualElementRadioButton(CellContext context, DevAge.Drawing.VisualElements.IRadioButton RadioButtonElement) { RadioButtonElement.AnchorArea = new DevAge.Drawing.AnchorArea(RadioButtonAlignment, false); Models.IRadioButton RadioButtonModel = (Models.IRadioButton)context.Cell.Model.FindModel(typeof(Models.IRadioButton)); Models.RadioButtonStatus RadioButtonStatus = RadioButtonModel.GetRadioButtonStatus(context); if (context.CellRange.Contains(context.Grid.MouseCellPosition)) { if (RadioButtonStatus.CheckEnable) { RadioButtonElement.Style = DevAge.Drawing.ControlDrawStyle.Hot; } else { RadioButtonElement.Style = DevAge.Drawing.ControlDrawStyle.Disabled; } } else { if (RadioButtonStatus.CheckEnable) { RadioButtonElement.Style = DevAge.Drawing.ControlDrawStyle.Normal; } else { RadioButtonElement.Style = DevAge.Drawing.ControlDrawStyle.Disabled; } } RadioButtonElement.RadioButtonState = RadioButtonStatus.CheckState; ElementText.Value = RadioButtonStatus.Caption; }
/// <summary> /// Toggle the value of the current cell and if AutoChangeValueOfSelectedCells is true of all the selected cells. /// Simulate an edit operation. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UIChangeChecked(CellContext sender, EventArgs e) { Models.IRadioButton l_Check = (Models.IRadioButton)sender.Cell.Model.FindModel(typeof(Models.IRadioButton));; if (l_Check == null) { throw new SourceGrid.SourceGridException("Models.IRadioButton not found"); } Models.RadioButtonStatus checkStatus = l_Check.GetRadioButtonStatus(sender); if (checkStatus.CheckEnable) { bool l_NewVal = !checkStatus.Checked; sender.StartEdit(); try { l_Check.SetCheckedValue(sender, l_NewVal); sender.EndEdit(false); } catch (Exception) { sender.EndEdit(true); throw; } //change the status of all selected control if (AutoChangeValueOfSelectedCells) { foreach (Position pos in sender.Grid.Selection.GetSelectionRegion().GetCellsPositions()) { Cells.ICellVirtual c = sender.Grid.GetCell(pos); Models.IRadioButton check; if (c != this && c != null && (check = (Models.IRadioButton)c.Model.FindModel(typeof(Models.IRadioButton))) != null) { CellContext context = new CellContext(sender.Grid, pos, c); context.StartEdit(); try { check.SetCheckedValue(context, l_NewVal); context.EndEdit(false); } catch (Exception) { context.EndEdit(true); throw; } } } } } }