I have used the Format property of the UltraGridColumn to set the format for my column, and this works as expected.
However, for one particular row in my grid I would like to format the contents of this column differently. Is there anyway to override the column formatting for a particular cell? Or, alternatively, is there any method I can call that will return me a formatted string if I pass in the format and a value?
Thanks.
Hello Kallan,
You can achieve this by using the initialize row event handler for the grid. Use an if statement to trap for the condition that requires different formatting.
Protected Sub theGrid_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles TheGrid.InitializeRow
To get a reference to the cell use:
e.Row.Cells.FromKey("The Key").Style.....
Hope it helps,
Patrick
Hi,
I understand that I can use the initialize row event to access the individual cell that I want to apply a different format to. However, I don't understand how I would use the Style property of the cell to do this. From examining the API of the GridItemStyle class there seem to be properties for setting colors, width, cssclass etc, but nothing to set the format of the cell. In my particular case I have set the column format to be "###########0" to display a number with no decimal places, but in one particular cell I would like to display the decimal places.
Can you give me any more pointers?
Thanks,
Kathryn
Hello,
Unfortunately the Format string is a property only for the parent Column, but not for each individual cell. The solution for this if you want to do it server-side, using the String.Format method, something along the lines of
cell.Value = System.String.Format("{0:C}", DataRow("Amount"))
Thanks, I will give that a go.
Hi
How do I translate this VB.Net?
Thank You.
MsBajanLady
For more granular control over the cell/row style, I use this code snippet ...
protected void uwgLCStats_InitializeRow(object sender, RowEventArgs e) { String CellText = ""; foreach (UltraGridCell Cell in e.Row.Cells) { CellText = Cell.Text.ToString(); GridItemStyle LableCSSClass = e.Row.Cells[0].Style; if (Cell.Text.Contains("~")) { Color FontColor = Color.FromArgb(0, 89, 59, 31); GridItemStyle RowCSSClass = e.Row.Style; RowCSSClass.BackgroundImage = "ig_res/Default/images/Caption_bg.jpg"; LableCSSClass.Padding.Left = Unit.Pixel(10); LableCSSClass.ForeColor = FontColor; LableCSSClass.Font.Bold = true; LableCSSClass.Font.Italic = true; CellText = Cell.Text.Replace("~", ""); Cell.Text = CellText; } else { LableCSSClass.Padding.Left = Unit.Pixel(25); //Indent group readings. } } }
I insert the "~" character in the cell text when the dataset is assembled as a way of flaging "special" cells.