We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Leading numbers in column

Hello,

in one of my colums in a GGC I have numbers from 10 to 100000.
Is it possible with the Format-property or with another way that I "fill up" every number with less than six characters to a number with at least six characters whereby I want to fill these numbers with leading "0" up to six characters.
For example:

10 ===> 000010
122 ===> 000122
12456 ===> 012456
123456 ===> 123456 (no change)

Thank you very much for any help

Karsten

4 Replies

AD Administrator Syncfusion Team September 20, 2006 05:32 AM UTC

Hi Karsten,

To specify a format on a cell, you can set style.Format and style.CellvalueType for the cell (or column in a GridDataBoundGrid or GridGroupingControl). But this will only display the problem when your user leaves the cell. It will not prevent him from typing anything. The Format property works with TextBox celltype only. Below is a code snippet

this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.CellType = "TextBox";
this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.CellValueType = typeof(int);
this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.Format = "000000";

Let me know if you are looking something different.

Thanks,
Haneef


KB Karsten Brocksieper September 20, 2006 08:37 AM UTC

Hi Haneef,

thank you for your response. But my problem is not to prevent the user from typing anything into the cell.
My problem is just to show (NO INPUT in the cell at all) the numbers in the cells with leading "0".
I fill the GGC with a datatable from an access database and in the underlying table there are the values without leading "0". And the only wish I have is to show the values in the GGC with leading "0".

Thank you very much for your help.
Karsten

>Hi Karsten,

To specify a format on a cell, you can set style.Format and style.CellvalueType for the cell (or column in a GridDataBoundGrid or GridGroupingControl). But this will only display the problem when your user leaves the cell. It will not prevent him from typing anything. The Format property works with TextBox celltype only. Below is a code snippet

this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.CellType = "TextBox";
this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.CellValueType = typeof(int);
this.grid.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.Format = "000000";

Let me know if you are looking something different.

Thanks,
Haneef


AD Administrator Syncfusion Team September 20, 2006 10:57 AM UTC

Hi Karsten,

You can handle the QueryCellFormattedText event of the grid and set the e.Text to some formatted value to want to display. Below is some code snippet.

private void QueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
GridTableCellStyleInfo style = e.Style as GridTableCellStyleInfo;

if( style != null && style.TableCellIdentity.Column != null
&& style.TableCellIdentity.Column.Name == "Col1" )
{
Element el = style.TableCellIdentity.DisplayElement;
if( el.Kind == DisplayElementKind.Record )
{
if( e.Value == null || e.Value.ToString() == string.Empty )
e.Text = "000000";
else
e.Text = string.Format("{0:000000}",e.Value);
e.Handled = true;
}
}
}

Sample : http://www.syncfusion.com/Support/user/uploads/GGCUpdate_e364cdc8.zip

Thanks,
Haneef


KB Karsten Brocksieper September 20, 2006 11:40 AM UTC

Hi Haneef,

...thank you very much for your help. That is exactly what I was searching for.

Regards,
Karsten

Loader.
Live Chat Icon For mobile
Up arrow icon