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

Limit currency cell''s maxlength at GDBG

Hi,

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
Borja

2 Replies

AD Administrator Syncfusion Team 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.

Regards,
Haneef


BO Borja September 12, 2006 07:08 AM UTC

It worked fine, thank you.

Loader.
Live Chat Icon For mobile
Up arrow icon