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.
Unfortunately, activation email could not send to your email. Please try again.

Need a decimal value validation

Thread ID:

Created:

Updated:

Platform:

Replies:

64308 Jul 18,2007 05:16 AM Jul 19,2007 04:07 PM Windows Forms 3
loading
Tags: GridControl
Nhilesh Baua
Asked On July 18, 2007 05:16 AM

Hello,

I am using GridControl 5.4.x.x.
I am binding cell data manually to every cell and I have entered following validation to have decimal values.

private void GridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{

int cIndex = grdStoreGrades.CurrentCell.ColIndex;
int rIndex = grdStoreGrades.CurrentCell.RowIndex;

if (cIndex == 5 || cIndex == 7)
{
if ((e.KeyChar != (char)Keys.Back) ||
(e.KeyChar != (char)Keys.Return) ||
(e.KeyChar != (char)Keys.Tab))
{
if (((e.KeyChar >= 48) && (e.KeyChar <= 57)) || e.KeyChar == 46)
{
if (grdStoreGrades[rIndex, cIndex].Text == "0")
{
grdStoreGrades[rIndex, cIndex].Text = "";
}
}
else
{
e.Handled = true;
}
}
}
}

How should I handle another dot(.) in the user entered values[though I am parsing the value in another event I want the user should not be able to enter another dot.]

can it be done with some cell formatting?

Please let me know.

Rajagopal [Syncfusion]
Replied On July 18, 2007 06:29 PM

Hi Nhilesh,

Thanks for your interest in Syncfusion Products.

Please try the code below in the CurrentCellValidateString event that gets fired for every key stroke, where you can valiadate the text that is enetered.

void gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (cc.ColIndex == 5 || cc.ColIndex == 7 )
{
double d;
if(!double.TryParse(e.Text, out d))
e.Cancel = true;
}
}

Let me know if this helps.

Have a nice time.
Regards,
Rajagopal

Nhilesh Baua
Replied On July 19, 2007 02:56 AM

Hi Rajagopal,

You are just a champ.
One small favour, I guess you will not mind.

Still can I restrict the user to enter values like 2.5 or 3.6 and not 2.589 and 3.652.

Yes I can always round them up but still I need a cake and not only a cream.

Thanks in advance.

- Nhilesh Baua.

haneefm [Syncfusion]
Replied On July 19, 2007 04:07 PM

Hi Nhilesh,

You can try these code :

void gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (cc.ColIndex == 5 || cc.ColIndex == 7)
{
double d;
int index = e.Text.IndexOf(".");
if ( !double.TryParse(e.Text, out d))
e.Cancel = true;
else if (index != -1 )
{
string s = e.Text.Substring(index);
e.Cancel = s.Length >2?true: false;
}

}
}

Best regards,
Haneef

CONFIRMATION

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.

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.

;