Datagridview单元格仅接受double值

时间:2016-12-05 04:54:45

标签: c# datagridview

我已将其设为整数值,并通过此代码及其工作:

 private void ItemsDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
    {

        DataGridViewTextBoxCell cell =ItemsDataGridView[2, e.RowIndex] as DataGridViewTextBoxCell;

        if (cell != null)
        {
            if (e.ColumnIndex == 2)
            {
                char[] chars = e.FormattedValue.ToString().ToCharArray();

                foreach (char c in chars)
                {
                    if (char.IsDigit(c) == false)
                    {
                        MessageBox.Show("You have to enter digits only");

                        e.Cancel = true;
                        break;
                    }
                }
            }

我想让另一个单元格接受双倍值以防止用户输入两个点"。"避免错误

0 个答案:

没有答案