private void gridViewWaste_BeforeEnterEditMode(object sender, CancelEventArgs e) { // Use the BeforeEnterEditMode event to position the edit controls UltraGridCell objCell = this.gridViewWaste.ActiveCell; // This should be impossible, but its good practice to check // to make sure there is an active cell before continuing if (objCell == null) { return; } // Get the UIElement associated with the active cell, which we will // need so we can get the size and location of the cell if (objCell.IsDataCell) { CellUIElement objCellUIElement = (CellUIElement)objCell.GetUIElement(this.gridViewWaste.ActiveRowScrollRegion, this.gridViewWaste.ActiveColScrollRegion); if (objCellUIElement == null) { return; } // Get the size and location of the cell int left = objCellUIElement.RectInsideBorders.Location.X + this.gridViewWaste.Location.X; int top = objCellUIElement.RectInsideBorders.Location.Y + this.gridViewWaste.Location.Y; int width = objCellUIElement.RectInsideBorders.Width; int height = objCellUIElement.RectInsideBorders.Height; // The edit control we will use depends on which column we are editing // The values of the identity fields are not very useful to the end user. // Let's display the name in these columns instead, // using the intrisic ComboBox control if (objCell.Column.Key == "FoodTypeID") { /* * // Set the combobox's size and location equal to the active cell's size and location * this.cboFoodName.SetBounds(left, top, width, height); * // Using the cell's value, select the appropriate item in the combobox * this.cboFoodName.SelectedValue = objCell.Value; * // Show the combobox control over the cell, and give it focus * cboFoodName.Visible = true; * cboFoodName.Focus(); * cboFoodName.BringToFront(); * * // Set the Cancel parameter to true so we don't actually go into edit mode * //e.Cancel = true; */ } else if (objCell.Column.Key == "Timestamp") { // Set the date picker's size and location equal to the active cell's size and location this.dtpStamp.SetBounds(left, top, dtpStamp.Width, dtpStamp.Height); // Set the value DateTime temp = DateTime.Parse(objCell.Value.ToString()); this.dtpStamp.Value = temp; this.dtpStamp.Visible = true; this.dtpStamp.Focus(); this.dtpStamp.BringToFront(); // Set the Cancel parameter to true so we don't actually go into edit mode //e.Cancel = true; } } }
private void ultraGrid1_BeforeEnterEditMode(object sender, CancelEventArgs e) { // Use the BeforeEnterEditMode event to position the edit controls UltraGridCell objCell = this.ultraGrid1.ActiveCell; // This should be impossible, but its good practice to check // to make sure there is an active cell before continuing if (objCell == null) { return; } // Get the UIElement associated with the active cell, which we will // need so we can get the size and location of the cell if (objCell.IsDataCell) { CellUIElement objCellUIElement = (CellUIElement)objCell.GetUIElement(this.ultraGrid1.ActiveRowScrollRegion, this.ultraGrid1.ActiveColScrollRegion); if (objCellUIElement == null) { return; } // Get the size and location of the cell int left = objCellUIElement.RectInsideBorders.Location.X + this.ultraGrid1.Location.X; int top = objCellUIElement.RectInsideBorders.Location.Y + this.ultraGrid1.Location.Y; int width = objCellUIElement.RectInsideBorders.Width; int height = objCellUIElement.RectInsideBorders.Height; // The edit control we will use depends on which column we are editing // The values of the identity fields are not very useful to the end user. // Let's display the name in these columns instead, // using the intrisic ComboBox control if (Regex.IsMatch(objCell.Column.Key, "TypeID")) { // Set the date picker's size and location equal to the active cell's size and location this.ucTreeView1.SetBounds(left, top, ucTreeView1.Width, ucTreeView1.Height); // Set the value this.ucTreeView1.InitTreeView(VWA4Common.GlobalSettings.CurrentTypeCatalogID.ToString(), Regex.Replace(objCell.Column.Key, "TypeID", ""), objCell.Value.ToString()); } else if (objCell.Column.Key == "FoodCostDiscount") { decimal value = cellValue(objCell.Value.ToString()); if (value != 0) { objCell.Value = value * 100m; } } } }
DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { UIElement element = drawParams.Element; // Look for an ImageUIElement if (element is ImageUIElement) { // Presumably, we only want to this images in cells // and not every image in the entire grid, so make sure it's in a cell. CellUIElement cellElement = element.GetAncestor(typeof(CellUIElement)) as CellUIElement; if (null != cellElement) { // We could also limit this to a particular column or columns. switch (cellElement.Cell.Column.Key) { case "Image": return(DrawPhase.BeforeDrawImage); } } } return(DrawPhase.None); }
public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { if (drawParams.Element is EmbeddableUIElementBase) { CellUIElement oCellUIElement = (CellUIElement)drawParams.Element.GetAncestor(typeof(CellUIElement)); UltraGridCell oCell = oCellUIElement.Cell; if (oCell == null || oCell.Column.Key.ToLower() != "percent") { return(false); } Rectangle rect = new Rectangle(); if (oCell.Value == null) { return(false); } int nCellWidth = drawParams.Element.RectInsideBorders.Width; int cellValue = Convert.ToInt32(oCell.Value); float percent = (float)(cellValue); percent = percent / (float)100; int nFillWidth = (int)(nCellWidth * percent); rect = new Rectangle(drawParams.Element.RectInsideBorders.X, drawParams.Element.RectInsideBorders.Y, nFillWidth, drawParams.Element.RectInsideBorders.Height); if (drawParams.DrawPhase == Infragistics.Win.DrawPhase.AfterDrawBackColor) { Brush brush = new SolidBrush(Color.DarkOrange); drawParams.Graphics.FillRectangle(brush, rect); Font font = drawParams.Font;//new Font("Arial", 9); string text = oCell.Value.ToString() + "%"; int nStringWidth = (int)drawParams.Graphics.MeasureString(text, font).Width; int left = oCellUIElement.RectInsideBorders.X + oCellUIElement.RectInsideBorders.Width / 2; left = left - nStringWidth / 2; int top = oCellUIElement.RectInsideBorders.Y; // If the text is going to be drawn over the flood filled area then make sure // the color is different from the flood color otherwise it won't show up. if (left < rect.Right) { brush.Dispose(); brush = new SolidBrush(Color.Black); } Brush brushFont = new SolidBrush(Color.Black); drawParams.Graphics.DrawString(text, font, brushFont, left, top); brush.Dispose(); return(true); } } return(false); }