954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Send Focus out of DataGridView

Dear Experts

DataGridView has 3 columns as

Sno----name----marks


While entering data, if sno column is empty and user press Enter or Tab then
Focus must go to me.textbox1

Please help

tqmd1
Junior Poster
151 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
 

Handle the DataGridView1.EditingControlShowing event,

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        dt.Columns.Add("No")
        dt.Columns.Add("Name")
        dt.Rows.Add(1, "A")
        dt.Rows.Add(2, "B")
        dt.Rows.Add(3, "C")
        DataGridView1.DataSource = dt

        AddHandler DataGridView1.EditingControlShowing, AddressOf MyEditHandler
End Sub


and from within the handler of EditingControlShowing, handles KeyUp event,

Sub MyEditHandler(ByVal s As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
        AddHandler e.Control.KeyUp, AddressOf MyKeyUpHandler
End Sub
Sub MyKeyUpHandler(ByVal s As Object, ByVal e As KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            TextBox1.Focus()
        End If
End Sub
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Sir,

May you did not read the question carefully.

how is about this

While entering data, if sno column is empty and user press Enter or Tab then Focus must go to me.textbox1


You wrote:

Sub MyKeyUpHandler(ByVal s As Object, ByVal e As KeyEventArgs)        If e.KeyCode = Keys.Enter Then            TextBox1.Focus()        End IfEnd SubSub MyKeyUpHandler(ByVal s As Object, ByVal e As KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            TextBox1.Focus()
        End If
End Sub


How to know that sno columns is empty?

tqmd1
Junior Poster
151 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
 

Add the handler for e.Control.Leave event and use CurrentCell.Value property of DataGridView to check the status.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: