GridTextColumn in sfDataGrid - limit max input length

Hi.

I'm using sfDataGrid control which has several columns (GridTextColumn). How to limit input text length in these columns? Each column has different max length in database, so the user should not be able to enter longer text in corresponding columns in datagrid.

Regards,

Chris


3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team July 26, 2021 09:51 AM UTC

Hi Chris, 

Thanks for contacting Syncfusion support.  

You can set maximum length for the GridTextColumn by creating a custom renderer as shown in the following code example.  

Code example :  

public Form1() 
{ 
    InitializeComponent(); 
    sfDataGrid1.DataSource = new OrderInfoCollection().OrdersListDetails; 
 
    this.sfDataGrid1.CellRenderers["TextBox"] = new GridTextBoxCellRendererExt(); 
} 
 
 
public class GridTextBoxCellRendererExt : GridTextBoxCellRenderer 
{ 
    protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, TextBox uiElement) 
    { 
        base.OnInitializeEditElement(column, rowColumnIndex, uiElement); 
 
        uiElement.MaxLength = 5; 
    } 
} 


Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

PI Piotr July 26, 2021 01:10 PM UTC

Your solution is working perfectly.

Thanks,

Chris



MA Mohanram Anbukkarasu Syncfusion Team July 27, 2021 05:40 AM UTC

Hi Chris, 

Thanks for the update.  

We are glad to know that the provided solution worked at your end. Please let us know if you require any other assistance from us. We are happy to help you.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon