Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27569

VS 2012 datagridview - unable to move around with 'enter' or arrow keys

$
0
0
Hi
I am trying to move from datagridview1 to datagridview2 and v.v. as per the code below
upon reaching last row cell and get the cursor blinking at the destination row/cell.
Any suggestions please ?

Code:


  ' 15 JAN 2014
'
' DATAGRIDVIEW trials
'
' fonts, alignment, width, color - MANAGED OK.
'
' SEEK TO :
' position cursor from end of dgv1 to start of dgv2 - USING ONLY THE ENTER KEY or the arrows up/down! - disable TAB !
' position cursor from end of dgv2 to start of dgv1 - USING ONLY THE ENTER KEY !
' display blinking cursor !
'
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        End
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Call DesignGridViews()
    End Sub
    Sub DesignGridViews()
        With dgv1
            .RowsDefaultCellStyle.SelectionForeColor = Color.Black
            .RowsDefaultCellStyle.SelectionBackColor = Color.Yellow
            .RowHeadersVisible = False
            .ColumnHeadersVisible = False
            For n = 0 To 1
                .Columns.AddRange(New DataGridViewTextBoxColumn())
                Select Case n
                    Case 0
                        .Columns(0).Name = "col0"
                        .Columns(0).Width = 100
                        .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                        .Columns(0).DefaultCellStyle.BackColor = Color.Gainsboro
                        .Columns(0).DefaultCellStyle.ForeColor = Color.Black
                    Case 1
                        .Columns(1).Name = "col1"
                        .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                        .Columns(1).Width = 120
                        .Columns(1).DefaultCellStyle.ForeColor = Color.Blue
                End Select
            Next
            .Columns(0).ReadOnly = True
            For n = 0 To 1
                Select Case n
                    Case 0 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                    Case 1 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                End Select
                .Item(1, n).Style.ForeColor = Color.Red
                .Item(1, n).Style.Font = New Font("Tahoma", 10, FontStyle.Bold)
            Next
            dgv1(0, 0).Selected = False
            dgv1(1, 0).Selected = True
            '------------------------------------
            .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
        End With
        '-----------------------------------------------------------------------------------------------------
        With dgv2
            .RowsDefaultCellStyle.SelectionForeColor = Color.Black
            .RowsDefaultCellStyle.SelectionBackColor = Color.Pink
            .RowHeadersVisible = False
            .ColumnHeadersVisible = False
            For n = 0 To 1
                .Columns.AddRange(New DataGridViewTextBoxColumn())
                Select Case n
                    Case 0
                        .Columns(0).Name = "col0"
                        .Columns(0).Width = 100
                        .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                        .Columns(0).DefaultCellStyle.BackColor = Color.Gainsboro
                        .Columns(0).DefaultCellStyle.ForeColor = Color.Black
                    Case 1
                        .Columns(1).Name = "col1"
                        .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                        .Columns(1).Width = 120
                        .Columns(1).DefaultCellStyle.ForeColor = Color.Blue
                End Select
            Next
            .Columns(0).ReadOnly = True
            For n = 0 To 3      ' counting rows...
                Select Case n
                    Case 0 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                    Case 1 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                    Case 2 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                    Case 3 : .Rows.Add("row " & CStr(n) & " item " & CStr(n) & " ->", "")
                End Select
                .Item(1, n).Style.ForeColor = Color.Red
                .Item(1, n).Style.Font = New Font("Tahoma", 10, FontStyle.Bold)
            Next
            dgv2(0, 0).Selected = False
            dgv2(1, 3).Selected = True
            '------------------------------------
            .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
        End With
    End Sub

    Private Sub dgv1_keyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dgv1.KeyUp
        Select Case e.KeyCode
            Case Keys.Enter
                If dgv1.CurrentCell.RowIndex = 1 Then dgv2(1, 0).Selected = True
                ' ERROR WITh ---->  .IsInEditMode = True    or  .PositionEditingControl = True
                ' selects Ok but no blinking cursor...
            Case Keys.Down
                ' seek code
            Case Keys.Up
                ' seek code
        End Select
    End Sub

    ' same pending for dgv2

End Class


Viewing all articles
Browse latest Browse all 27569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>