Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Could not Focus Cell In DataGridView

Could not Focus Cell In DataGridView

Scheduled Pinned Locked Moved Visual Basic
regex
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rhtbhegade
    wrote on last edited by
    #1

    Hi Experts, After my validation my control goes to the next cell..I have written the code to focus the current cell.But could not get the same.... code is ---> Private Sub dgvstock_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvstock.CellValidating Dim cell As DataGridViewCell = dgvstock.Item(e.ColumnIndex, e.RowIndex) Dim ret As Integer If cell.IsInEditMode Then Dim c As Control = dgvstock.EditingControl Select Case dgvstock.Columns(e.ColumnIndex).Name Case "Sr No.", "Amount" c.Text = CleanInputNumber(c.Text) If c.Text = "" Then ret = MessageBox.Show("Enter Only Numbers", "Invalid Input") If ret = 1 Then dgvstock.CurrentCell = dgvstock(e.ColumnIndex, e.RowIndex) //Here i want the focus on current cell End If End If End Select End If End Sub Private Function CleanInputAlphabet(ByVal str As String) As String Return System.Text.RegularExpressions.Regex.Replace(str, "[0-9\b\s-]", "") End Function

    S 2 Replies Last reply
    0
    • R rhtbhegade

      Hi Experts, After my validation my control goes to the next cell..I have written the code to focus the current cell.But could not get the same.... code is ---> Private Sub dgvstock_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvstock.CellValidating Dim cell As DataGridViewCell = dgvstock.Item(e.ColumnIndex, e.RowIndex) Dim ret As Integer If cell.IsInEditMode Then Dim c As Control = dgvstock.EditingControl Select Case dgvstock.Columns(e.ColumnIndex).Name Case "Sr No.", "Amount" c.Text = CleanInputNumber(c.Text) If c.Text = "" Then ret = MessageBox.Show("Enter Only Numbers", "Invalid Input") If ret = 1 Then dgvstock.CurrentCell = dgvstock(e.ColumnIndex, e.RowIndex) //Here i want the focus on current cell End If End If End Select End If End Sub Private Function CleanInputAlphabet(ByVal str As String) As String Return System.Text.RegularExpressions.Regex.Replace(str, "[0-9\b\s-]", "") End Function

      S Offline
      S Offline
      Sreyas M N
      wrote on last edited by
      #2

      //This will written in the EditingControlShowing event of datagridview If TypeOf e.Control Is TextBox Then DirectCast(e.Control, TextBox).CharacterCasing = CharacterCasing.Upper End If

      1 Reply Last reply
      0
      • R rhtbhegade

        Hi Experts, After my validation my control goes to the next cell..I have written the code to focus the current cell.But could not get the same.... code is ---> Private Sub dgvstock_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvstock.CellValidating Dim cell As DataGridViewCell = dgvstock.Item(e.ColumnIndex, e.RowIndex) Dim ret As Integer If cell.IsInEditMode Then Dim c As Control = dgvstock.EditingControl Select Case dgvstock.Columns(e.ColumnIndex).Name Case "Sr No.", "Amount" c.Text = CleanInputNumber(c.Text) If c.Text = "" Then ret = MessageBox.Show("Enter Only Numbers", "Invalid Input") If ret = 1 Then dgvstock.CurrentCell = dgvstock(e.ColumnIndex, e.RowIndex) //Here i want the focus on current cell End If End If End Select End If End Sub Private Function CleanInputAlphabet(ByVal str As String) As String Return System.Text.RegularExpressions.Regex.Replace(str, "[0-9\b\s-]", "") End Function

        S Offline
        S Offline
        Sreyas M N
        wrote on last edited by
        #3

        Datagridview1.CurrentCell = Datagridview1('Your column index', Datagridview1.NewRowIndex) Datagridview1.BeginEdit(True)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups