Tuesday, January 29, 2013

Enter only Numeric data in Datagridview in c#


private void DgviewStock_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 10))
            {
                string value = DgviewStock.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                foreach (char c in value)
                {
                    if (!char.IsDigit(c))
                    {
                        MessageBox.Show("Please enter numeric value.");
                        DgviewStock.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = string.Empty;
                        return;
                    }
                }
            }
        }

No comments:

Post a Comment