Handling Negative Values in Bounded Grid

Hello
I have a bounded grid . The Cell type is Currency . I have writtem the code as

Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CellType = "Currency"
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.CurrencyNumberDigits = 3
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.CurrencyDecimalDigits = 1
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.CurrencySymbol = ""
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.NullString = ""
The problem is If i put a Negative value then in that case the cell text gets RED . Is there any way I can restric the user to put negative values . I hope I have made u understand the problem .

Regards
Lokesh

3 Replies

AD Administrator Syncfusion Team November 21, 2006 11:20 AM UTC

Hi Lokesh,

The following code states how to set the NegativeSign, NegativeColor and CurrencyNegativePattern of the currency cell in a grid. Please try this and let me know if you are looking something different.

Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.NegativeColor = Color.Black
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.NegativeSign = string.Empty;
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.CurrencyNegativePattern = 1;

Best Regards,
Haneef


LO Lokesh November 21, 2006 12:05 PM UTC

Hello Haneef
Thanks for the Answer but I dont want the user to put any negative values . That means my grid cell should accept only positive values .

regards
lokesh


>Hi Lokesh,

The following code states how to set the NegativeSign, NegativeColor and CurrencyNegativePattern of the currency cell in a grid. Please try this and let me know if you are looking something different.

Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.NegativeColor = Color.Black
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.NegativeSign = string.Empty;
Qualification.GridBoundColumns(GridColumns.ScheduledHours).StyleInfo.CurrencyEdit.CurrencyNegativePattern = 1;

Best Regards,
Haneef


AD Administrator Syncfusion Team November 21, 2006 12:53 PM UTC

Hi Lokesh,

You can acess the GridCurrencyTextBox control and handle the CurrencyTextBox.KeyValidate event to cancel the '-' key in a currency cell. Here is a code snippet to show this.

private void gridDataBoundGrid1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
{
GridCurrencyTextBox cCurrencyTextBox = e.Control as GridCurrencyTextBox;
if( cCurrencyTextBox != null)
cCurrencyTextBox.KeyValidate +=new KeyValidateEventHandler(cCurrencyTextBox_KeyValidate);
}
private void cCurrencyTextBox_KeyValidate(object sender, KeyValidateEventArgs e)
{
if( e.Key == '-')
e.Cancel = true;
}

Best Regards,
Haneef

Loader.
Up arrow icon