How make certain datagridview column to only accept numeric value in C#
<p>The following code makes <code>DataGridView</code> <code>Column4</code> to only accept numeric value and one decimal dot <code>.</code> and it works fine for example it accepts values such as (4.50 , 3.00 , 13.60)</p>

<p>But the problem is: I still can save a decimal dot by itself inside the cell (Without any numbers just the decimal dot) and I do not want the cell to have only decimal dot because the sql database (money column) do not accept only decimal dot. </p>

<p>Any one knows how to prevent the cells in <code>Column4</code> to not accept only decimal dot but to accept values like: (4.50 , 3.00 , 13.60) ?</p>

<p>please help Thank you</p>

<pre><code> private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        e.Control.KeyPress -= new KeyPressEventHandler(AnyColumnKeyPress);
        if (dataGridView1.CurrentCell.ColumnIndex == 4 ) //Desired Column
        {
            TextBox tb = e.Control as TextBox;
            if (tb != null)
            {
                tb.KeyPress += new KeyPressEventHandler(AnyColumnKeyPress);
            }



        }
    }

    private void AnyColumnKeyPress(object sender, KeyPressEventArgs e)
    {
        if (!char.IsControl(e.KeyChar) &amp;&amp; !char.IsDigit(e.KeyChar) &amp;&amp; e.KeyChar != '.')
        {
            e.Handled = true;
        }

        // allow 1 dot:


        if ((e.KeyChar == '.') &amp;&amp; ((sender as TextBox).Text.IndexOf('.') &gt; -1))
        {
            e.Handled = true;
        }



    }
</code></pre>