Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
good evening....

i have a problem...
ie.

i wrote a code in gridveiw_cell validating event..like below
C#
private void gridStoreIssues_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
       {
           try
           {
               if (e.RowIndex != -1 && e.ColumnIndex == colIsuQty.Index && ((StoreTransaction)gridStoreIssues.Rows[e.RowIndex].DataBoundItem) != null)
               {
                   if (colIndQty.Visible && Convert.ToSingle(e.FormattedValue) > Convert.ToSingle(gridStoreIssues[colIndQty.Index, e.RowIndex].Value))
                   {
                       Console.Beep();
                       e.Cancel = true;
                       MessageBox.Show("Issue Qty Cannot Exceed Indent Qty");
                       StatusBar.Text = "Issue Qty Cannot Exceed Indent Qty";
                       gridStoreIssues.CurrentCell = gridStoreIssues[colIsuQty.Index, e.RowIndex];
                       gridStoreIssues.BeginEdit(true);
                   }
                   else if (Math.Round(Convert.ToSingle(e.FormattedValue), 3) > Math.Round(((StoreTransaction)gridStoreIssues.Rows[e.RowIndex].DataBoundItem).QuantityOnHand, 3))
                   {
                       Console.Beep();
                       DialogResult dr = MessageBox.Show(string.Format("The Issued qty is over the available qty of {0:N3}.", Math.Round(((StoreTransaction)gridStoreIssues.Rows[e.RowIndex].DataBoundItem).QuantityOnHand, 3)), "Continue", MessageBoxButtons.OK, MessageBoxIcon.Information);

                       if (dr == DialogResult.OK)
                       {
                           e.Cancel = true;
                           gridStoreIssues.BeginEdit(true);
                       }
                       else
                           e.Cancel = false;
                   }
               }
           }
           catch (Exception ex)
           {
              // StoreTransFactory.GenerateExceptionTextFile(ServerTime.Now + ",StoreIssueForm," + this.Name + "," + ex.Message + "," + ex.StackTrace + "\n", Application.StartupPath + @"\Store.txt");
           }
       }


its working fine in my system..
but in my clint system give a exception like bellow

16:31:08,StoreIssueForm,StoreIssueForm,Input string was not in a correct format., at System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToSingle(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToSingle(IFormatProvider provider)
at System.Convert.ToSingle(Object value)
at Prosynergix.Store.StoreIssueForm.gridStoreIssues_CellValidating(Object sender, DataGridViewCellValidatingEventArgs e)

i dont know why it was gave exception...
any one plz help me...
Posted

1 solution

This is because the comma (to separate the int part from the fractional part) for floats are represented differently depending on the regional settings. For example 1.5 in USA will be 1,5 in France.

ToString or float.Parse or ConvertToSingle methods (and more) use the regional settings. If you want to have the same results in any country then use CultureInfo.InvariantCulture as a parameter for these functions.
 
Share this answer
 
v2
Comments
ajitha.pusapati 14-Mar-11 9:19am    
thanks for ur replay...
i will try at my Clint sys...
Sergey Alexandrovich Kryukov 14-Mar-11 16:24pm    
Sure, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900