Hi everyone,
I'm wondering if it is possible to format the contents of a checkbox column.
My DTO has a boolean field, ultragrid automatically assigns a checkbox to the column.
I've been given the assignment to provide column formatting on this grid. So instead of just showing the checkbox, now I have to show the text "Full: " followed by the checkbox. Is this possible?
To make things even harder, the column has to be editable.
Kind regards!
Tobias
Hi Tobias,
TobiasV said:is there a way that I can show the text AND checkbox in the MiddleCenter?
Yes, but not by a simple property setting. To do this, you would have to use a CreationFilter and adjust the UIElements yourself.
This seems to work pretty well. But note that Autosizing the column has no way to account for a CreationFilter, so you will probably want to set the column to a fixed width.
private void Form1_Load(object sender, EventArgs e) { this.ultraCheckEditor1.Text = "Full: "; this.ultraCheckEditor1.CheckAlign = ContentAlignment.MiddleCenter; this.ultraGrid1.CreationFilter = new MyCheckBoxCenteringCreationFilter(); } private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand band = layout.Bands[0]; band.Columns["Column 1"].EditorComponent = this.ultraCheckEditor1; }
public class MyCheckBoxCenteringCreationFilter : IUIElementCreationFilter { void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if (parent is CheckEditorCheckBoxUIElement) { TextUIElement textElement = parent.GetDescendant(typeof(TextUIElement)) as TextUIElement; UIElement checkIndicatorElement = parent.GetDescendant(typeof(CheckIndicatorUIElement)); textElement.TextVAlign = VAlign.Middle; Rectangle parentRect = parent.Rect; Rectangle textRect = textElement.Rect; // Center the text vertically textRect.X = parentRect.X; textRect.Y = parentRect.Y; textRect.Height = parentRect.Height; textElement.Rect = textRect; } } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { // do nothing return false; } }
It works! :) Thanks again for the swift reply!
I have one question though. If I use your code but change the ContentAlignment of the CheckAlign to MiddleCenter then the checkbox is correct but my text appears in the BottomLeft, is there a way that I can show the text AND checkbox in the MiddleCenter?
Very much appreciated!
Tobias Vandenbempt
Yes, I think this is possible. Do you just want the same text in every cell of the column? Or does the text vary from row to row?If you want the same text in every cell, then it's pretty easy. You just attach an UltraCheckEditor to to cell.
private void Form1_Load(object sender, EventArgs e) { this.ultraCheckEditor1.Text = "Full: "; this.ultraCheckEditor1.CheckAlign = ContentAlignment.MiddleRight; } private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand band = layout.Bands[0]; band.Columns["Column 1"].EditorComponent = this.ultraCheckEditor1; }