none
DataGridView EDITING and EDITING in VB 6.0 DataGrid

    Question

  • Hello
    I am using VB2005 and developed an application which have a datagridview.. I am enabling the editing in the datagridview cells. But the problem is in the vb6.0 Datagrid there are two events present that are BeforeColEdit and AfterColEdit,
    In the VB2005 equivalent of these two functions are as follows.
    BeforeColEdit === CellBeginEdit
    and
    AfterColEdit ==== CellEndEdit

    The following article of Microsoft's MSDN says that BeforeColEdit equals to CellBeginEdit
    and AfterColEdit equals to CellEndEdit.
    http://msdn2.microsoft.com/en-us/library/y4ddh1ac%28vs.80%29.aspx


    I am using CellBeginEdit and CellEndEdit, but the poroblem is in the vb6.0 functions
    BeforeColEdit is called when user press any key in the Cell otherwise no action will be performed.
    and
    the AfterColEdit called when user leaving the cell .. if the user edited the value of the cell then the AfterColEdit function will be called else no action will be perfromed and the value of the cell remains as previously it was.

    BUT in VB2005 CellBeinEdit is called when user enters in any cell and CellEndEdit will be called when user leaves the row.. irrespective of the editing of the cell.

    I want the functionality the events that is present in the datagrid of VB6.0 in VB2005's datagridview.
    That means CellBeginEdit Should be called when user press any key in the cell .. remeber if user is typein 2000 in the cell then when user will press the 2 then the CellBeinEdit should be called else after nothing will be performed. and
    in the case of CellEndEdit the event will be called when user leaving the row and if he have done any change in the value of the cell.

    Plz help me.........
    Thursday, May 31, 2007 9:59 AM

Answers

  •  

    Hi prashant_victory,

     

    JeroGrav's explanation about CellBeginEdit event is perfect.Do you want something like this. The DataGridView is setted to Edit Mode only if user types the first letter from the keyboard. Try like this.

     

    Code Snippet

    namespace DGV

    {

        public partial class Form4 : Form

        {

            public Form4()

            {

                InitializeComponent();

            }

     

            private void Form4_Load(object sender, EventArgs e)

            {

        this.dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;

                this.employeesTableAdapter1.Fill(this.dataSet11.Employees);

                this.dataGridView1.CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit);

            }

     

           

            void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)

            {

                MessageBox.Show("Editing");

            }

     

            private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)

            {

                if (Char.IsLetterOrDigit(e.KeyChar) || Char.IsPunctuation(e.KeyChar) ||e.KeyChar == ' ')

                {

                    this.dataGridView1.BeginEdit(true);

                }

            }

        }

    }

     

    Hope this helps.

     

    Regards

    Wednesday, June 06, 2007 6:10 AM

All replies

  • I think you will have to abandon comparing the CellBeginEdit / CellEndEdit with those events from the DataGrid. They do similar things, but as you have seen, they have some subtle differences.

     

    The default behaviour of the DataGridView is *not* to go into edit mode when entering a cell.

    Its usually pretty easy to tell if the DataGridView is in edit mode or not. If the current cell is hilighted in blue then it's *not* in edit mode. But if it is in edit mode you will see what looks like a normal TextBox with the flashing caret (for a TextBoxCell).

     

    If you are getting the CellBeginEdit as soon as you enter the cell then it is going into edit mode as soon as you enter the cell. This sort of thing is usually caused by user code.

     

    Regards

    Thursday, May 31, 2007 8:32 PM
  • Hello,

    Actually I knwo when its vsisble that datagridview in edit mode and when its not,

    I want when user enters in the cell then the CellBeginedit will not be called.. it will be called when user will start typing and it only calls once when user types the first letter from the keyboard after that it will not to be called.

    Friday, June 01, 2007 3:39 PM
  • By default a DataGridView will not go into edit mode as soon as you enter a new cell. It will go into edit mode when you start typing or deliberately enter edit mode (such as pressing the F2 key).

    When you do enter edit mode, it will trigger a single CellBeginEdit event. You won't get a CellBeginEdit event each time you type a letter.

     

    If you are seeing some different behaviour then it is most likely that you have got some code in your app that is doing that for you without you realising it.

     

    Regards

    Monday, June 04, 2007 9:33 PM
  •  

    Hi prashant_victory,

     

    JeroGrav's explanation about CellBeginEdit event is perfect.Do you want something like this. The DataGridView is setted to Edit Mode only if user types the first letter from the keyboard. Try like this.

     

    Code Snippet

    namespace DGV

    {

        public partial class Form4 : Form

        {

            public Form4()

            {

                InitializeComponent();

            }

     

            private void Form4_Load(object sender, EventArgs e)

            {

        this.dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;

                this.employeesTableAdapter1.Fill(this.dataSet11.Employees);

                this.dataGridView1.CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit);

            }

     

           

            void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)

            {

                MessageBox.Show("Editing");

            }

     

            private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)

            {

                if (Char.IsLetterOrDigit(e.KeyChar) || Char.IsPunctuation(e.KeyChar) ||e.KeyChar == ' ')

                {

                    this.dataGridView1.BeginEdit(true);

                }

            }

        }

    }

     

    Hope this helps.

     

    Regards

    Wednesday, June 06, 2007 6:10 AM