private DataGridViewTextBoxEditingControl CellEdit = null; // 声明 一个 CellEdit
        private void dgvConsume_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            CellEdit = (DataGridViewTextBoxEditingControl)e.Control;
            CellEdit.SelectAll();
            CellEdit.KeyPress += Cells_KeyPress;
        }
        private void Cells_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (dataGridView1.Columns[dgvConsume.CurrentCell.ColumnIndex].Name.Equals("kjmoney"))
            {
                if ((Convert.ToInt32(e.KeyChar) < 48 || Convert.ToInt32(e.KeyChar) > 57) && Convert.ToInt32(e.KeyChar) != 46 && Convert.ToInt32(e.KeyChar) != 8 && Convert.ToInt32(e.KeyChar) != 13)
                {
                    e.Handled = true;
                }
                else
                {
                    if ((Convert.ToInt32(e.KeyChar) == 46))
                    {
                        e.Handled = true;
                    }
                }
            }
        }

posted on 2013-09-22 17:29  xalyf  阅读(284)  评论(0)    收藏  举报