Advertisement
Aveneid

VB autocomplete

Sep 1st, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Dim tb As New TextBox
  2.  Dim dt As New DataTable
  3.  If DataGridView1.CurrentCell.ColumnIndex = 2 Then
  4.             If con.State = ConnectionState.Closed Then con.Open()
  5.             cmd = New SqlCeCommand("Select name FROM items where name like '%" & DataGridView1.CurrentCell.Value & "%'", con)
  6.             Dim da As New SqlCeDataAdapter
  7.             da.SelectCommand = cmd
  8.             da.Fill(dt)
  9.             Dim r As DataRow
  10.             For Each r In dt.Rows
  11.                 If TypeOf e.Control Is TextBox Then
  12.                     If DataGridView1.CurrentCell.ColumnIndex = 2 Then
  13.                         tb = e.Control
  14.                         tb.AutoCompleteCustomSource.Add(r.Item("name").ToString)
  15.                         tb.AutoCompleteMode = AutoCompleteMode.Suggest
  16.                         tb.AutoCompleteSource = AutoCompleteSource.CustomSource
  17.                     End If
  18.                 End If
  19.             Next
  20.             da.Dispose()
  21.             cmd.Dispose()
  22.             dt.Dispose()
  23.             con.Close()
  24.         End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement