Vba 在另一个schenario中,自动图文集声明通常放置在Events中,end然后使用自动图文集的previewkeyevent运行If e.KeyCode=Keys的代码。然后输入DataGridView1.EndEdit(),进行验证,最后一次设置单元格
Vba 在另一个schenario中,自动图文集声明通常放置在Events中,end然后使用自动图文集的previewkeyevent运行If e.KeyCode=Keys的代码。然后输入DataGridView1.EndEdit(),进行验证,最后一次设置单元格,vba,vb.net,visual-studio,datagridview,autocomplete,Vba,Vb.net,Visual Studio,Datagridview,Autocomplete,在另一个schenario中,自动图文集声明通常放置在Events中,end然后使用自动图文集的previewkeyevent运行If e.KeyCode=Keys的代码。然后输入DataGridView1.EndEdit(),进行验证,最后一次设置单元格的位置,示例:DataGridView1.CurrentCell=DataGridView1.Item(1,0),如果 Private Sub getData(ByVal DataCol As AutoCompleteStringCollect
在另一个schenario中,自动图文集声明通常放置在Events中,end然后使用自动图文集的previewkeyevent运行If e.KeyCode=Keys的代码。然后输入DataGridView1.EndEdit(),进行验证,最后一次设置单元格的位置,示例:DataGridView1.CurrentCell=DataGridView1.Item(1,0),如果
Private Sub getData(ByVal DataCol As AutoCompleteStringCollection)
Dim comm As SqlCommand
Dim adapt As New SqlDataAdapter
Dim ds As New DataSet
Dim sql As String = "SELECT DISTINCT ValueOption From HR.dbo.RecruitVal WHERE ColumnName = 'Source'"
Try
If SqlConn.State = ConnectionState.Broken Then SqlConn.Close()
If SqlConn.State = ConnectionState.Closed Then SqlConn.Open()
comm = New SqlCommand(sql, SqlConn)
adapt.SelectCommand = comm
adapt.Fill(ds)
adapt.Dispose()
comm.Dispose()
For Each row As DataRow In ds.Tables(0).Rows
DataCol.Add(row(0).ToString())
Next
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub RAppSrc(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles RAppGrid.EditingControlShowing
Dim titleText As String = RAppGrid.Columns(RAppGrid.CurrentCell.ColumnIndex).HeaderText
If titleText.Equals("Source") Then
Dim autoText As TextBox = TryCast(e.Control, TextBox)
If autoText IsNot Nothing Then
autoText.AutoCompleteMode = AutoCompleteMode.SuggestAppend
autoText.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim dataCol As New AutoCompleteStringCollection()
getData(dataCol)
autoText.AutoCompleteCustomSource = dataCol
End If
End If
End Sub
If (appCol.Name = "Source") Then
Dim sql As String = " SELECT 1 FROM Hr.dbo.RecruitVal WHERE ColumnName = 'Source'AND ValueOption = @Source "
Dim sql2 As String = "SELECT DISTINCT ValueOption from HR.dbo.RecruitVal WHERE ColumnName = 'Source' "
Dim com As New SqlCommand(sql, SqlConn)
Dim com2 As New SqlCommand(sql2, SqlConn)
Dim reader As SqlDataReader
Dim val As String
Dim val2 As String
com.Parameters.Add("@Source", SqlDbType.VarChar).Value = e.FormattedValue
val = com.ExecuteScalar()
reader = com2.ExecuteReader()
If reader.HasRows Then
While reader.Read()
val2 += reader.GetValue(0) & "," & Space(3)
End While
End If
If String.IsNullOrEmpty(e.FormattedValue) Then
'Do Nothing
ElseIf val = Nothing Then
MessageBox.Show(" Please Enter a valid Source Option" & vbCrLf & vbCrLf & "Valid Options are as Follows:" & vbCrLf & vbCrLf + val2.ToString(), "VALIDATION ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
RAppGrid.EndEdit()
End If
End If
{
Keys key = (e.KeyCode & Keys::KeyCode); //removes control, alt modifiers
if(key == Keys.Enter)
{
//Still do the default processing for enter so it will move down to the next row
Base.ProcessDataGridViewKey(e);
return false; //say we have *not* handled the key
}
else
{
return Base.ProcessDataGridViewKey(e);
}
}
Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If IsNothing(TryCast(e.Control, DataGridViewTextBoxEditingControl)) = False Then
Dim tb As DataGridViewTextBoxEditingControl = e.Control
AddHandler e.Control.KeyDown, AddressOf DataGridView1_Keydown
End If
End Sub
Private Sub DataGridView1_Keydown(sender As Object, e As KeyEventArgs) ' Handles DataGridView1.KeyDown
Dim dgv As DataGridView = DataGridView1
Dim tb As TextBox = CType(sender, TextBox)
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
dgv.EndEdit()
If IsNothing(dgv.CurrentCell) = False Then
Dim cc As DataGridViewCell = dgv.CurrentCell
If cc.ColumnIndex < dgv.Columns.Count - 2 Then ' if there's a cell to the right of the current one
dgv.CurrentCell = dgv.Rows(cc.RowIndex).Cells(cc.ColumnIndex + 1)
ElseIf cc.RowIndex < dgv.Rows.Count - 1 Then ' if there's a row bellow
dgv.CurrentCell = dgv.Rows(cc.RowIndex + 1).Cells(0)
Else
' do nothing, stay where you are
End If
dgv.CurrentCell.Selected = True
End If
End If
End Sub