Hi,
I am using a gridgroupingcontrol. In one of the column, I am using mask. The format I need is ####-####. Here is what I have done,
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.CellType = "MaskEdit";
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.MaskEdit.Mask = "####-####";
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.MaskEdit.PaddingCharacter = '0';
The issue I face is, if the column has only 7 digits like 1234567 it pads with a trailing zero, so it becomes 12345670, whereas I want a padding with leading zero like 01234567.
Is there a way to do this. Let me know if you need any more information on this.
Thanks
Manoj
AD
Administrator
Syncfusion Team
November 10, 2006 06:59 AM UTC
Hi Manoj,
This is the default behavior of the MaskEdit cell type, however to get the desired behavior, you can use DrawCellDisplayText event and set the e.DispalyText to some new value to want to display. Here is a code snippet
private void gridDrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if( e.Style.CellType == "MaskEdit"
&& e.Style.Text != e.DisplayText )
{
int iTrailZero = e.DisplayText.Length - e.Style.Text.Length;
string sTrailZero = string.Empty;
for(int i= 1;i sTrailZero += '0';
e.DisplayText = sTrailZero + e.DisplayText.Substring(0,e.DisplayText.Length-iTrailZero + 1);
}
}
Best Regards,
Haneef
MB
Manoj Bhaskarakurup
November 11, 2006 01:02 AM UTC
Hi,
Thanks for the reply, but the code does not work as expected. It changes the mask after to #####-### after prefixing with a zero using this code. The expected mask is ####-####.
Thanks
Manoj
>Hi,
I am using a gridgroupingcontrol. In one of the column, I am using mask. The format I need is ####-####. Here is what I have done,
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.CellType = "MaskEdit";
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.MaskEdit.Mask = "####-####";
gridColumnDescriptor3.Appearance.AnyRecordFieldCell.MaskEdit.PaddingCharacter = '0';
The issue I face is, if the column has only 7 digits like 1234567 it pads with a trailing zero, so it becomes 12345670, whereas I want a padding with leading zero like 01234567.
Is there a way to do this. Let me know if you need any more information on this.
Thanks
Manoj
AD
Administrator
Syncfusion Team
November 13, 2006 04:35 AM UTC
Hi Manoj,
You can use string.Replace method to replace the "-" string to String.Empty andthen insert the "-" string at 4th place of the e.DisplayText. Below is a code snippet
private void gridControl1_DrawCellDisplayText(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellDisplayTextEventArgs e)
{
if( e.Style.CellType == "MaskEdit"
&& e.Style.Text != e.DisplayText )
{
int iTrailZero = e.DisplayText.Length - e.Style.Text.Length;
string sTrailZero = string.Empty;
for(int i = 1;i sTrailZero += '0';
e.DisplayText = sTrailZero + e.DisplayText.Substring(0,e.DisplayText.Length-iTrailZero + 1);
e.DisplayText = e.DisplayText.Replace("-",string.Empty);
e.DisplayText = e.DisplayText.Insert( 4,"-");
}
}
Best Regards,
Haneef