Need a decimal value validation
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.
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.
SIGN IN To post a reply.
3 Replies
RA
Rajagopal
Syncfusion Team
July 18, 2007 10:29 PM UTC
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.
Let me know if this helps.
Have a nice time.
Regards,
Rajagopal
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
NB
Nhilesh Baua
July 19, 2007 06:56 AM UTC
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.
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.
HA
haneefm
Syncfusion Team
July 19, 2007 08:07 PM UTC
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
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
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
NB Nhilesh Baua
- Jul 18, 2007 09:16 AM UTC
- Jul 19, 2007 08:07 PM UTC