Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2007, 02:48 PM
Authorized User
 
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGridViewTextBoxEditingControl adding numeric t

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();
            }

        }
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?






Similar Threads
Thread Thread Starter Forum Replies Last Post
From numeric to alfa numeric ebekir XSLT 1 August 10th, 2007 06:13 AM
How can i know it's NUMERIC deco Beginning VB 6 1 April 23rd, 2007 06:19 AM
HELP!! Numeric Textbox value quentinuys HTML Code Clinic 3 December 18th, 2006 08:04 AM
Adding Numeric TextBox Values virajoza HTML Code Clinic 1 December 18th, 2006 07:59 AM
Numeric Up Down Kunkel General .NET 0 April 16th, 2004 10:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.