Click here to Skip to main content
15,792,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am trying to insert cell data from another datagrid when i press "Enter" in parent datagrid .

I tried below code but not working when editing cell , otherwise there is no issue.

How can i get the value when in editing mode. There is something to do with EditingControlShowing but i am not getting it how to do.

What I have tried:

VB
Private Sub DgvJournal_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DgvJournal.KeyPress
        Dim keyChar As Char = e.KeyChar
        If AscW(keyChar) = 13 Then
            DgvJournal.Rows(DgvJournal.CurrentCell.RowIndex).Cells(0).Value = DgvMainAccountList.Rows(0).Cells(0).Value

        End If

    End Sub

    Private Sub DgvJournal_KeyDown(sender As Object, e As KeyEventArgs) Handles DgvJournal.KeyDown
        If e.KeyCode = Keys.Enter Then
            DgvJournal.Rows(DgvJournal.CurrentCell.RowIndex).Cells(0).Value = DgvMainAccountList.Rows(0).Cells(0).Value
        End If
    End Sub

    Private Sub DgvJournal_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles DgvJournal.PreviewKeyDown
        If e.KeyCode = Keys.Enter Then
            DgvJournal.Rows(DgvJournal.CurrentCell.RowIndex).Cells(0).Value = DgvMainAccountList.Rows(0).Cells(0).Value
        End If
    End Sub

    Private Sub FrmJournal_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown

        If DgvJournal.Focused Then
            If e.KeyCode = Keys.Enter Then
                DgvJournal.Rows(DgvJournal.CurrentCell.RowIndex).Cells(0).Value = DgvMainAccountList.Rows(0).Cells(0).Value
            End If

        End If

    End Sub
Posted
Updated 5-Jun-20 4:30am
v2

1 solution

Basically, don't. ENTER is a key with a specific use: to submit the form or end an edit. And users are used to that. If you start faffing with familiar design elements, you users will hate your app, and probably uninstall it.

And it's that "Submit" action that is probably causing your problem - the ENTER key is being "swallowed" by the form and never reaching your DGV ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900