DataGridView - Cell Capture, Cursor Focus, Cursor Leave, and Edit - VB.NET 2005

Giganews Newsgroups
Subject: DataGridView - Cell Capture, Cursor Focus, Cursor Leave, and Edit - VB.NET 2005
Posted by:  Harry.SQLserv…@gmail.com (Harry.SQLserv…@gmail.com)
Date: Fri, 23 May 2008

Hi Linda and Jeffrey,

Thank you very much for your posta! When I run the following modified
code Linda provided, and enter "a" on the first cell of the first row
the message box still appears twice with "a" in it. This happens on
all the cells. I guess this is not a biggie... I have two additional
questions for both of you:

1 - How can I make the cursor blink in the first cell/column of the
first row once I open/load the form? ? I managed to take the focus to
first cell/column of the first row once I open/load the form. But I do
not know how to make the cursor blink. Can you help?

2 - Also, could you give me the code and tell me how to move the
cursor to the first cell/column of the SECOND row once the 'Enter' key
is pressed in the first cell/column of the first row?

Please reply here or on Harry.SQLServer AT gmail DOT com

Here is the complete code that I have:

Public Class frmSampleReceipt
    Inherits System.Windows.Forms.Form

    Dim txtbox As System.Windows.Forms.TextBox = Nothing

    Public Sub New()
        InitializeComponent()
        Me.MdiParent = SPP.frmMainMenu
        SPP.frmMainMenu.Show()
    End Sub

    Private Sub frmSampleReceipt_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
        FormPosition(Me)
        AddHandler dgvReceipt.EditingControlShowing, AddressOf
dgvReceipt_EditingControlShowing
        AddHandler dgvReceipt.CellLeave, AddressOf
dgvReceipt_CellLeave
        Me.dgvReceipt.RowCount = 20
        Me.dgvReceipt.CurrentCell = Me.dgvReceipt.Item("SampleID", 0)
    End Sub

    Private Sub dgvReceipt_CellLeave(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgvReceipt.CellLeave
        If Not (txtbox Is Nothing) Then
            RemoveHandler txtbox.KeyPress, AddressOf txtBox_KeyPress
        End If
    End Sub

    Private Sub txtBox_KeyPress(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.KeyPressEventArgs)
        MsgBox(e.KeyChar.ToString())
    End Sub

    Private Sub dgvReceipt_EditingControlShowing(ByVal sender As
Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlShowingEventArgs)
Handles dgvReceipt.EditingControlShowing
        txtbox = CType(e.Control, System.Windows.Forms.TextBox)
        If Not (txtbox Is Nothing) Then
          AddHandler txtbox.KeyPress, AddressOf txtBox_KeyPress
        End If
    End Sub

End Class

Thank you very much in advance!
Harry

Replies