Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

ProcessCmdKey detect leave cell to process.

Hi Experts,

I have below code.

   Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If Not blnGridOnFocus Then
            Return MyBase.ProcessCmdKey(msg, keyData)
        End If


        If keyData = Keys.Enter Or keyData = Keys.Tab Then

            With dgvBarang

                .EndEdit(True)

                Dim dgvRow As DataGridViewRow
                dgvRow = .Rows(.CurrentRow.Index)

                Dim strColumnName As String = ERV_Global.Get_Column_Name_From_Datagridview(
                         dgvBarang,
                         .CurrentCell.ColumnIndex)

                Select Case strColumnName

                    Case "HargaSatuan"

                        If Not IsNumeric(dgvRow.Cells("HargaSatuan").Value) Then
                            dgvRow.Cells("HargaSatuan").Value = 0
                            .Rows(.CurrentRow.Index).Cells("SatuanCode").Value = .Rows(.CurrentRow.Index).Cells("SatuanCode").Value
                        End If

                        .CurrentCell = .Rows(.CurrentRow.Index).Cells("SatuanCode")

                    Case "SatuanCode"

                        If .CurrentRow.Index < .Rows.Count - 1 Then
                            .CurrentCell = .Rows(.CurrentCell.RowIndex + 1).Cells("HargaSatuan")
                        Else

                            cboForGrid.Visible = False

                            btnSave.Focus()
                            Return True

                        End If

                    Case Else
                        SendKeys.Send("{TAB}")
                        .CurrentCell = .Rows(.CurrentCell.RowIndex).Cells(.CurrentCell.ColumnIndex)
                End Select

                .BeginEdit(True)

                blnGridOnFocus = True
            End With

            Return True
        Else
            Return MyBase.ProcessCmdKey(msg, keyData)

        End If

    End Function

Open in new window


This is only works for Enter and Tab.

How could I allow leaving cell (Enter, Tab, Mouse) to process the function ?

Thank you.
Avatar of Deja Anbu
Deja Anbu
Flag of Oman image

What about using datagridview mouseleave event?
Avatar of emi_sastra
emi_sastra

ASKER

- What about using datagridview mouseleave event?
And what to do ?

Thank you.
Sorry, did you try writing the same functionality in datagridview_cellMouseLeave event?
-Sorry, did you try writing the same functionality in datagridview_cellMouseLeave event?
Not yet, what should code at that event?

Thank you.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.