/// <summary> /// Initialises a new instance of ComboTreeDropDown and associates it with its parent ComboTreeBox. /// </summary> /// <param name="sourceControl"></param> public ComboTreeDropDown(ComboTreeBox sourceControl) { _visibleItems = new List <NodeInfo>(); _bitmaps = new Dictionary <BitmapInfo, Image>(); _scrollBar = new ScrollBarInfo(); AutoSize = false; this._sourceControl = sourceControl; RenderMode = ToolStripRenderMode.System; BackColor = Color.White; _dropDownHeight = 150; _itemHeight = MIN_ITEM_HEIGHT; Items.Add(""); _scrollRepeater = new Timer(); _scrollRepeater.Tick += new EventHandler(scrollRepeater_Tick); }
/// <summary> /// Paints the cell. /// </summary> /// <param name="graphics"></param> /// <param name="clipBounds"></param> /// <param name="cellBounds"></param> /// <param name="rowIndex"></param> /// <param name="cellState"></param> /// <param name="value"></param> /// <param name="formattedValue"></param> /// <param name="errorText"></param> /// <param name="cellStyle"></param> /// <param name="advancedBorderStyle"></param> /// <param name="paintParts"></param> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); BeforePaintContent(graphics, cellBounds, cellState, cellStyle, paintParts); if (paintParts.HasFlag(DataGridViewPaintParts.ContentForeground)) { ComboTreeBoxColumn column = (ComboTreeBoxColumn)OwningColumn; ComboTreeNode node = Nodes.ParsePath(Convert.ToString(formattedValue), column.PathSeparator, column.UseNodeNamesForPath); string displayValue; if (column.ShowPath) { displayValue = Convert.ToString(formattedValue); } else { displayValue = (node != null) ? node.Text : String.Empty; } Image img = ComboTreeBox.GetNodeImage(node, column.Images, column.ImageIndex, column.ImageKey, column.ExpandedImageIndex, column.ExpandedImageKey); Rectangle contentBounds = cellBounds; contentBounds.Width -= 17; TextFormatFlags flags = ComboTreeBox.TEXT_FORMAT_FLAGS | TextFormatFlags.PreserveGraphicsClipping; Rectangle imgBounds = (img == null) ? new Rectangle(Point.Add(contentBounds.Location, new Size(1, 0)), Size.Empty) : new Rectangle(contentBounds.Left + 4, contentBounds.Top + (contentBounds.Height / 2 - img.Height / 2), img.Width, img.Height); Rectangle txtBounds = new Rectangle(imgBounds.Right, contentBounds.Top, contentBounds.Right - imgBounds.Right - 3, contentBounds.Height); if (img != null) { graphics.DrawImage(img, imgBounds); } TextRenderer.DrawText(graphics, displayValue, cellStyle.Font, txtBounds, cellStyle.ForeColor, flags); } AfterPaintContent(graphics, clipBounds, cellBounds, rowIndex, cellStyle, advancedBorderStyle, paintParts); }
public static void LoadComboTreeBoxList_(ComboTreeBox prmDropDownList, List <KeyValueDTOForTree> prmDataSource = null, DropDownListAction?prmDropDownListAction = null) { prmDropDownList.Nodes.Clear(); KeyValueDTOForTree firstItem = null; if (prmDropDownListAction != null) { switch (prmDropDownListAction) { case DropDownListAction.All: firstItem = new KeyValueDTOForTree() { Id = Constants.AllValue, Value1 = Constants.All }; break; case DropDownListAction.Select: firstItem = new KeyValueDTOForTree() { Id = Constants.SelectValue, Value1 = Constants.Select }; break; } } if (prmDataSource != null) { prmDropDownList.Nodes.AddRange(ProcessDataForComboTreeBox(prmDataSource, prmDataSource[0].ParentId)); } if (firstItem != null) { ComboTreeNode firstNode = new ComboTreeNode(firstItem.Value1); firstNode.Tag = firstItem.Id; prmDropDownList.Nodes.Insert(0, firstNode); prmDropDownList.SelectedNode = firstNode; } prmDropDownList.ExpandAll(); }