Prikazi cijelu temu 09.03.2018 12:01
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Lokacija:-


Predmet:Re: Enter kao tab u DataGridView kako?
Probao sam i sa custom. Tu me prabaci za 2 polja desno ako ima edit polja a ako nema vrati me na prvo polje master forme. Evo cod

Public Class CustomDataGridView
Inherits DataGridView

Dim celWasEndEdit As DataGridViewCell
Private _EnterMoveNext As Boolean = True

<System.ComponentModel.DefaultValue(True)> _
Public Property OnEnterKeyMoveNext() As Boolean
Get
Return Me._EnterMoveNext
End Get
Set(ByVal value As Boolean)
Me._EnterMoveNext = value
End Set
End Property

Private Sub DataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Me.CellEndEdit
Me.celWasEndEdit = Me(e.ColumnIndex, e.RowIndex)
End Sub

Private Sub DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SelectionChanged
' if Enter Move Next should work andalso
' mouse button was NOT down
' we are checking mouse buttons because if select was changed
' by Mouse then we will NOT do our Enter Move Next
If Me._EnterMoveNext AndAlso MouseButtons = 0 Then
' if selection is changed after Cell Editing
If Me.celWasEndEdit IsNot Nothing AndAlso _
Me.CurrentCell IsNot Nothing Then
' if we are currently in the next line of last edit cell
If Me.CurrentCell.RowIndex = Me.celWasEndEdit.RowIndex + 1 AndAlso _
Me.CurrentCell.ColumnIndex = Me.celWasEndEdit.ColumnIndex Then
Dim iColNew As Integer
Dim iRowNew As Integer
' if we at the last column
If Me.celWasEndEdit.ColumnIndex >= Me.ColumnCount - 1 Then
iColNew = 0 ' move to first column
iRowNew = Me.CurrentCell.RowIndex ' and move to next row
Else ' else it means we are NOT at the last column
' move to next column
iColNew = Me.celWasEndEdit.ColumnIndex + 1
' but row should remain same
iRowNew = Me.celWasEndEdit.RowIndex
End If
Me.CurrentCell = Me(iColNew, iRowNew) ' ok set the current column
End If
End If
Me.celWasEndEdit = Nothing ' reset the cell end edit
End If
End Sub

End Class