Results 1 to 6 of 6

Thread: [RESOLVED] How to select a cell in datagridview?

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [RESOLVED] How to select a cell in datagridview?

    I have a dgv with 14 columns.

    If i'm in dgv.item(8,0) in edit mode
    What code can i use to jump to (12,0) and also enter editmode.

    I call it editmode, dont know what the actual term is . Its the state where you can enter a value into that cell

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: How to select a cell in datagridview?

    Datagridview.CurrentCell = Datagridview.Rows(12).Cells(0)

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: How to select a cell in datagridview?

    The code you provided only selects the cell, but doesn't enter "editmode". I still have to click the cell before I can enter any data into that cell.

    2nd problem I encountered was this error.
    Name:  VB ERROR.jpg
Views: 30991
Size:  28.1 KB

    Any Ideas?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to select a cell in datagridview?

    Why is your code in the CellLeave event handler? Also, this:
    Code:
    Datagridview.Rows(12).Cells(0)
    is more simply done like this:
    Code:
    Datagridview(0, 12)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: How to select a cell in datagridview?

    This is only my test project. In my main project it works like this:

    The first column is the important one. After the user selected a value from the DatagridviewComboBoxColumn in column(0) it loads certain data from a table in the database. Then it defaults the values of some of the other columns.

    99.99% of the time the values that have been defaulted wont need changing, so my goal is to skip the defaulted columns and jump directly into the important ones. This will make it easier for the user to capture data.

  6. #6

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: How to select a cell in datagridview?

    I found a way.

    Here it is
    vb Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         intActivate = 1
    3.     End Sub
    4.  
    5.     Dim intActivate As Integer = 0
    6.     Dim WishedForCell As DataGridViewCell = Nothing
    7.     Private Sub dgvPrice_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellValueChanged
    8.         If e.ColumnIndex = 0 Then
    9.             If intActivate = 1 Then
    10.                 Static RedirectingCell As Boolean = False
    11.                 If Not RedirectingCell Then
    12.                     If e.ColumnIndex = 0 Then
    13.                         RedirectingCell = True
    14.                         WishedForCell = dgv.Item(2, e.RowIndex)
    15.                     End If
    16.                 End If
    17.                 RedirectingCell = False
    18.             End If
    19.         End If
    20.     End Sub
    21.  
    22.     Private Sub dgvPrice_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgv.KeyUp
    23.         If WishedForCell IsNot Nothing Then
    24.             Me.dgv.CurrentCell = WishedForCell
    25.             WishedForCell = Nothing
    26.         End If
    27.     End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width