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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Limit currency cell''s maxlength at GDBG

Thread ID:





49103 Sep 11,2006 04:47 PM UTC Sep 12,2006 07:08 AM UTC WinForms 2
Tags: GridControl
Asked On September 11, 2006 04:47 PM UTC


I''m using a GridDataBoundGrid which have columns which cellType is Currency. I need to limit the amount or the number of characters. I have tried e.Style.MaxLength = 15 at Model_QueryCellInfo event (it works for other types of cells) but it doesn''t work. How can i set the maxlength of the column?

Thank you

Administrator [Syncfusion]
Replied On September 12, 2006 03:36 AM UTC

Hi Borja,

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

For Currency celltypes, you would have to set the GridStyleInfo.CurrecyEdit.CurrencyDecimalDigits and the GridStyleInfo.CurrecyEdit.CurrencyNumberDigits properties of the cell. The CurrencyDecimalDigits sets the maximum number of digits for the decimal portion of the currency. The CurrencyNumberDigits set the number of digits for the number part. Below is a code snippet.

//for column 2:
this.grid.ColStyle[2].CurrencyEdit.CurrencyDecimalDigits = 0;
this.grid.ColStyle[2].CurrencyEdit.CurrencyNumberDigits = 5;

//QueryCellInfo event cell.
e.Style.CurrencyEdit.CurrencyDecimalDigits = 0;
e.Style.CurrencyEdit.CurrencyNumberDigits = 5;

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

Private Sub GridDataBoundGrid1_CurrentCellKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles GridDataBoundGrid1.CurrentCellKeyPress
Dim cc As GridCurrentCell = Me.GridDataBoundGrid1.CurrentCell
If cc.Renderer.ControlText.Length >= Me.GridDataBoundGrid1(cc.RowIndex, cc.ColIndex).MaxLength Then
e.Handled = True
End If
End Sub

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


Replied On September 12, 2006 07:08 AM UTC

It worked fine, thank you.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon