restrict max lenght of cell in ggc

i am using syncfusion ggc. i want to restrict the string entered by user to max 100 character. I mean user should not be able to type more than 100 characters. I am using the following code which is not working.

GridStyleInfo colStyleInfo = this.gridControl1.ColStyles[1];
colStyleInfo.MaxLength = 5;

One more thing that my editable cell is of type "GridListControl"

this.ggc.TableDescriptor.Columns["colName"].Appearance.AnyRecordFieldCell.CellType = "GridListControl";



1 Reply

HA haneefm Syncfusion Team January 3, 2008 06:52 PM UTC

Hi Prabhjeet,

The GridStyleInfo.MaxLength properly is only used with the TextBox cell type.

For other cell types, you would have to handle things yourself. A straight-forward way of doing this is to handle the TableControlCurrentCellKeyPress event and set e.Inner.Handled if the current string is to long. Below is a code snippet.

private void gridGroupingControl1_TableControlCurrentCellKeyPress(object sender, GridTableControlKeyPressEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
if (cc.Renderer.ControlText.Length > 100)
{
e.Inner.Handled = true;
}
}

Let me know if something like this will not work for you.

Best regards,
Haneef


Loader.
Up arrow icon