/// <summary>Try to find the specific grid control. If the control is not found it will be created.</summary> /// <param name="gridcontroltype">The gridcontroltype.</param> /// <param name="childname">The childname.</param> /// <param name="blocktype">The blocktype.</param> /// <param name="created">if set to <c>true</c> [created].</param> /// <returns></returns> private IGridControl GridControl_Get(enGrid_ControlType gridcontroltype, string childname, enGrid_BlockType blocktype, out bool created) { created = false; IGridControl gridControl; if (GridControl_Get(childname, out gridControl)) { return(gridControl); // The control was found -> work is done. } // We need to create the control if (gridcontroltype == enGrid_ControlType.Row) { #region Create a new row var row = new GridControl_Row(); _gridControls.Add(childname, row); gridControl = row; #endregion } else { if (blocktype == enGrid_BlockType.MicroBlock) { #region Create micro grid var micro = new GridControl_BlockMicro(); _gridControls.Add(childname, micro); gridControl = micro; #endregion } else { #region Create sub or macro grid block var grid = new GridControl_Block(); _gridControls.Add(childname, grid); gridControl = grid; #endregion } } gridControl.Name = childname; // Set the name gridControl.SuspendLayout(); // Optimise performance created = true; // Set flag return(gridControl); }
private string ControlToStr(enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype) { var type = gridcontroltype.ToString(); return(type + "//" + parentname + "//" + childname + "//" + blocktype); }
private void OnCreateGridControl1(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype, ref IGridControl gridcontrol) { //gridcontrol = new object() as IGridControl; _ListTest1.Add(ControlToStr(gridcontroltype, parentname, childname, blocktype)); }
private void onCreateGridControl(IGridBlock_Base sender, enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype, ref IGridControl gridcontrol) { if (gridcontrol != null) { throw new ArgumentException(nameof(gridcontrol), "Error!. Grid control must be null in order to be created."); } #region Sample of a simple 1x1,1x1,1x1 grid // R1 // R1cub1_1 // R1cub1_1R1 // R1cub1_1R1mac1_1 // R1cub1_1R1mac1_1R1 // R1cub1_1R1mac1_1R1sub1_1 // R1cub1_1R1mac1_1R1sub1_1R1 // R1cub1_1R1mac1_1R1sub1_1R1mic1_1 // Row//?//R1//CuboidGrid // Grid//R1//R1cub1_1//CuboidGrid // Row//R1cub1_1//R1cub1_1R1//MacroBlock // Grid//R1cub1_1R1//R1cub1_1R1mac1_1//MacroBlock // Row//R1cub1_1R1mac1_1//R1cub1_1R1mac1_1R1//SubBlock // Grid//R1cub1_1R1mac1_1R1//R1cub1_1R1mac1_1R1sub1_1//SubBlock // Row//R1cub1_1R1mac1_1R1sub1_1//R1cub1_1R1mac1_1R1sub1_1R1//MicroBlock // Grid//R1cub1_1R1mac1_1R1sub1_1R1//R1cub1_1R1mac1_1R1sub1_1R1mic1_1//MicroBlock #endregion // Find the grid control bool created; gridcontrol = GridControl_Get(gridcontroltype, childname, blocktype, out created); if (created == false) { return; // The control exists, we do not need to do anything. } // Find the parent IGridControl parent; if (GridControl_Get(parentname, out parent) == false) { throw new InvalidOperationException($"Error! Parent '{parentname}' does not exist."); } // Setup the row / grid properties gridcontrol.GridState = sender; gridcontrol.Text = sender.Name_Caption; // Set the caption of the control if (gridcontroltype == enGrid_ControlType.Row) { #region Row setup // ================== int height = 100; if (blocktype == enGrid_BlockType.CuboidGrid) { height = _Settings.Size_CuboidHeight; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.MacroBlock) { height = _Settings.Size_MacroHeight; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.SubBlock) { height = _Settings.Size_SubHeight; } else if (blocktype == enGrid_BlockType.MicroBlock) { height = _Settings.Size_MicroHeight; } GridControl_SetupRow(parent, gridcontrol, height); #endregion } else { #region Grid setup // =================== var color = Color.Gray; int width = 30; if (blocktype == enGrid_BlockType.CuboidGrid) { color = _Settings.ColorDefault_CuboidGrid; width = _Settings.Size_CuboidWidth; // These settings need to be calculated } else if (blocktype == enGrid_BlockType.MacroBlock) { width = _Settings.Size_MacroWidth; // These settings need to be calculated color = _Settings.ColorDefault_MacroGrid; } else if (blocktype == enGrid_BlockType.SubBlock) { width = _Settings.Size_SubWidth; color = _Settings.ColorDefault_SubGrid; } else if (blocktype == enGrid_BlockType.MicroBlock) { var display = _Settings.DisplayMode_MicroGrids; if (display == enGrid_BlockDisplayType.Address) { gridcontrol.Text = sender.Name_Caption; // Set the caption of the control } if (display == enGrid_BlockDisplayType.Name) { gridcontrol.Text = sender.Name_Control; // Set the caption of the control } if (display == enGrid_BlockDisplayType.Value) { gridcontrol.Text = "?"; //There is no value yet } width = _Settings.Size_MicroWidth; color = _Settings.ColorDefault_MicroGrid; } GridControl_SetupBlock(parent, gridcontrol, width, color); #endregion } }
public static string GridControl_2Str(enGrid_ControlType gridcontroltype, string parentname, string childname, enGrid_BlockType blocktype) { var type = gridcontroltype.ToString(); return(type + "//" + parentname + "//" + childname + "//" + blocktype); }