datagridviewcell in editmode

pettrer

Well-known member
Joined
Sep 5, 2008
Messages
92
Programming Experience
10+
Hi all,

I'm having trouble with setting a datagridview's cell in edit mode, or rather, to let the user type some input on load of a form (as in Excel or the like).

This is my code (after the dgv has been filled):
VB.NET:
dgvTentander.EditMode = DataGridViewEditMode.EditProgrammatically
'(or dgvTentander.EditMode = DataGridViewEditMode.EditOnEnter)
dgvMyDGV.CurrentCell = dgvMYDGV.Rows(lastrow).Cells(TeCOL_Quant)
dgvMYDGV.BeginEdit(True)

The code correctly indicates that the cell is selected, and when the page is loaded I can still se the cell selected, but the cursor doesn't appear and nothing happens when I type. What am I missing?

Thanks a lot,

Pettrer
 
Last edited:
does dgvMYDGV.BeginEdit(True) return true?

Hi,

Thanks for replying.

Yes, it does (at least this gives True):
VB.NET:
  Dim ghasjd As Boolean = dgvMYDGV.BeginEdit(True)
  MsgBox(ghasjd)

This is the last thing that happens in the code. The correct cell looks to be in editmode, that is, the rest of the row is blue (selected color) but the cell is white. It's just that the cursor doesn't appear and that the keystrokes aren't recognised. If I forcibly set the dgv to cellselect (dgvMYDGV.SelectionMode = DataGridViewSelectionMode.CellSelect), the same thing happens, (even though the row doesn't turn blue, of course).

Thanks again,

Pettrer
 
Last edited:
Hi again,

For testing purposes I created a new project, with a single form and a dgv in it, with some columns added to it, and the rest left as per default. This is the code I added in the VB file:

VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.Rows.Add()
        DataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect
        'SelectionMode can be omitted - doesn't seem to matter

        DataGridView1.CurrentCell = DataGridView1.Rows(2).Cells(0)
        DataGridView1.BeginEdit(True)
    End Sub
End Class

So it seems like I'm missing something very obvious, as I'm sure this should have set the cursor correctly.

What am I doing wrong?

/Pettrer
 
Back
Top