locked
DataGridView > How can I set a selected cell in edit mode

    Question

  • How can I set the selected cell in the edit mode ?

    DetailDataGridView.Focus()
    DetailBindingSource.AddNew()
    Dim I As Integer
    I = DetailDataGridView.CurrentRow.Index
    DetailDataGridView.Rows(I).Cells(3).Selected = True

    So far so good but the question now is: How can I set the cell in the edit mode

    Thanks in advance
    Dante

    Monday, September 12, 2011 7:14 PM

Answers

  • Hi dantehavenaar,

    Welcome to MSDN forum.

    Based on your description, my understanding is that you need to start the cell in edit mode automatically. In my opinion, at first, you can set the current cell to which you want to edit. And then the cell will be in the edit mode automatically.  And if there are other controls in your form and the tabindex property of datagridview control is not the smallest one, you need make the DataGridView control to be focused.  Here is a sample code.

      DataGridView1.Select()
      DataGridView1.CurrentCell = DataGridView1(2, 0)
    

    If you have any concerns, please feel free to let me know.


    Mark lxf [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 14, 2011 9:07 AM
    Moderator

All replies

  • Hello dantehavenaar,

    How can I set the selected cell in the edit mode ?

    DetailDataGridView.Focus()
    DetailBindingSource.AddNew()
    Dim I AsInteger
    I = DetailDataGridView.CurrentRow.Index
    DetailDataGridView.Rows(I).Cells(3).Selected = True

    So far so good but the question now is: How can I set the cell in the edit mode

    Thanks in advance
    Dante

     hope you understand, you select a cell in edit mode, in which case you need to use BeginEdit and pass as a parameter to True to put the current cell in edit mode.

     

      Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            Me.DataGridView1.BeginEdit(True)
        End Sub
    

     Regards.

     


    Carmelo La Monica

    Blog http://community.visual-basic.it/carmelolamonica/

    WordPress http://carmelolamonica.wordpress.com/

    Twitter  http://twitter.com/carmelolamonica

    Monday, September 12, 2011 8:14 PM
  • Hi Carmelo,

    You don't need that code because when you click in a cell the edit mode will start automatically.
    I have a textbox and read data with a barcode reader. A barcode reader generates automatically a return.
    After the return I add a new record to the datagridview and fill the first 2 cells with data.
    Then I select the 3th cell. I want to start that cell in edit mode automatically, not with a mouse click.
    I have tryed to put the BeginEdit in the Datagridview Enter event but that doesn't work.

    I hope this clarifies it for you?
    Cheers,
    Dante

    Tuesday, September 13, 2011 6:28 PM
  • Hi dantehavenaar,

    Welcome to MSDN forum.

    Based on your description, my understanding is that you need to start the cell in edit mode automatically. In my opinion, at first, you can set the current cell to which you want to edit. And then the cell will be in the edit mode automatically.  And if there are other controls in your form and the tabindex property of datagridview control is not the smallest one, you need make the DataGridView control to be focused.  Here is a sample code.

      DataGridView1.Select()
      DataGridView1.CurrentCell = DataGridView1(2, 0)
    

    If you have any concerns, please feel free to let me know.


    Mark lxf [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 14, 2011 9:07 AM
    Moderator
  • Hi DanteHavenaan

    try this

    DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter


    Be a good forum member. Make this forum a great place to meet and interact with others around the world.
    Wednesday, September 14, 2011 5:08 PM