DataGridViewTextBoxEditingControl adding numeric text inside

Aug 14 2007 3:54 PM
I have the following code

[CODE]

/// Puts the current cell in edit mode.
 private void monitorDataGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            validFormat = true;
            monitorDataGrid.EditMode = DataGridViewEditMode.EditOnEnter;
            //monitorDataGrid.BeginEdit(false);
        }

       /// Occurs when a control for editing a cell is showing.
        /// Performs custom initialization of the editing control when a cell enters edit mode
        private void monitorDataGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            mKeyUpController.Clear();
            Control ctl = e.Control;

            DataGridViewTextBoxEditingControl dText = (DataGridViewTextBoxEditingControl)ctl;
            dText.EditingControlDataGridView.EditMode = DataGridViewEditMode.EditOnEnter;
            dText.KeyDown += new KeyEventHandler(dText_KeyDown);
            dText.KeyUp += new KeyEventHandler(dText_KeyUp);
        }

void dText_KeyDown(object sender, KeyEventArgs e)
        {
            monitorDataGrid.CurrentCell.ErrorText = String.Empty;

            if (e.KeyData == Keys.OemPeriod || e.KeyData == Keys.Decimal)
            {

            }
            else if (
                     ((int)e.KeyCode >= (int)Keys.D0 && (int)e.KeyCode <= (int)Keys.D9) ||
                     ((int)e.KeyCode >= (int)Keys.NumPad0 && (int)e.KeyCode <= (int)Keys.NumPad9)
                    )
            {  
                DataGridViewTextBoxEditingControl dText = (DataGridViewTextBoxEditingControl)sender;

                e.Handled = false;

                // This is needed for text to go 123 instead of 321
                dText.PrepareEditingControlForEdit(false);
                dText.DeselectAll();
            }
           
        }

[/CODE]

For some reason when i run this code if i press a button and the button put an error text in my cell, when i go back , it selects all the text (something selects it not me ) and if i type a number, it will add a number at the end of the current number in the cell

For example
I have in a datagridviewcell the value 1.000

I press a button and puts an error text in the datagridviewcell

i go back and select the value 1.000 and if i press 2 it will put
1.001
if i press 2 again it will put
1.002
if i press 2 again it will put
1.003

** Disclaimer : There's nothing in my code that adds the current value of the cell ... I believe this is a bug of this control

The point is that there's a bug either in my code or in the control that causes this
what should happen is that if i press 2 it should either delete 1.000 and put 2 , or simply append the 2 at the end

ANY THOUGHTS ON WHAT IS CAUSING THIS?