Ben Sebuabe

Ben Sebuabe

  • NA
  • 4
  • 5.6k

BindingSource with comboboxes using Autocomplete feature

Apr 23 2014 1:23 PM
Please, I'm using vb.net ultimate 2013 and I have about 15 comboboxes being populated with data at runtime.
Now, I used a "for loop"to add autocomplete feature to the comboboxes and it takes a longer time to load the form as a  result of the "for loop", looping through each combo box to add the autocomplete feature. I thought of  a binding source but how to implement it becomes a problem. Is there any quick way to to add the auto complete feature at runtime? That's my code below.
 
 
 
 'Connection already set
SQLCon.ConnectionString = DataL1
SqlQuery = "Select * from Users order by UserName asc"
dSet1 = New DataSet : dSet2 = New DataSet : dSet3 = New DataSet : dSet4 = New DataSet
dSet5 = New DataSet : dSet6 = New DataSet : dSet7 = New DataSet : dSet8 = New DataSet
dSet9 = New DataSet : dSet10 = New DataSet : dSet11 = New DataSet : dSet12 = New DataSet
dSet13 = New DataSet : dSet14 = New DataSet : dSet15 = New DataSet
dTable = New DataSet
daAdapterRec = New SqlDataAdapter
daAdapter1 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter2 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter3 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter4 = New SqlDataAdapter(SqlQuery, SQLCon)
daAdapter5 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter6 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter7 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter8 = New SqlDataAdapter(SqlQuery, SQLCon)
daAdapter9 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter10 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter11 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter12 = New SqlDataAdapter(SqlQuery, SQLCon)
daAdapter13 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter14 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter15 = New SqlDataAdapter(SqlQuery, SQLCon)
daAdapter = New SqlDataAdapter(SqlQuery, SQLCon)
Try
daAdapter1.Fill(dSet1, "Users") : daAdapter2.Fill(dSet2, "Users") : daAdapter3.Fill(dSet3, "Users") : daAdapter4.Fill(dSet4, "Users") : daAdapter5.Fill(dSet5, "Users") : daAdapter5.Fill(dSet5, "Users")
daAdapter6.Fill(dSet6, "Users") : daAdapter7.Fill(dSet7, "Users") : daAdapter8.Fill(dSet8, "Users") : daAdapter9.Fill(dSet9, "Users") : daAdapter10.Fill(dSet10, "Users") : daAdapter11.Fill(dSet11, "Users")
daAdapter12.Fill(dSet12, "Users") : daAdapter13.Fill(dSet13, "Users") : daAdapter14.Fill(dSet14, "Users") : daAdapter15.Fill(dSet15, "Users")
daAdapter.Fill(dTable, "Users")
'From1
frmtracking.cboFrom1.DataSource = dTable.Tables("Users")
frmtracking.cboFrom1.DisplayMember = "UserName"
frmTracking.cboFrom1.Text = frmVisibleNot.txtUsername.Text.Trim
'To1
frmtracking.cboTo1.DataSource = dSet1.Tables("Users")
frmtracking.cboTo1.DisplayMember = "UserName"
'To2
frmtracking.cboTo2.DataSource = dSet2.Tables("Users")
frmtracking.cboTo2.DisplayMember = "UserName"
'To3
frmtracking.cboTo3.DataSource = dSet3.Tables("Users")
frmtracking.cboTo3.DisplayMember = "UserName"
'To4
frmtracking.cboTo4.DataSource = dSet4.Tables("Users")
frmtracking.cboTo4.DisplayMember = "UserName"
'To5
frmtracking.cboTo5.DataSource = dSet5.Tables("Users")
frmtracking.cboTo5.DisplayMember = "UserName"
'To6
frmtracking.cboTo6.DataSource = dSet6.Tables("Users")
frmtracking.cboTo6.DisplayMember = "UserName"
'To7
frmtracking.cboTo7.DataSource = dSet7.Tables("Users")
frmtracking.cboTo7.DisplayMember = "UserName"
'To8
frmtracking.cboTo8.DataSource = dSet8.Tables("Users")
frmtracking.cboTo8.DisplayMember = "UserName"
'To9
frmtracking.cboTo9.DataSource = dSet9.Tables("Users")
frmtracking.cboTo9.DisplayMember = "UserName"
'To10
frmtracking.cboTo10.DataSource = dSet10.Tables("Users")
frmtracking.cboTo10.DisplayMember = "UserName"
'To11
frmtracking.cboTo11.DataSource = dSet11.Tables("Users")
frmtracking.cboTo11.DisplayMember = "UserName"
'To12
frmtracking.cboTo12.DataSource = dSet12.Tables("Users")
frmtracking.cboTo12.DisplayMember = "UserName"
frmtracking.cboTo12.Text = ""
'To13
frmtracking.cboTo13.DataSource = dSet13.Tables("Users")
frmtracking.cboTo13.DisplayMember = "UserName"
'To14
frmtracking.cboTo14.DataSource = dSet14.Tables("Users")
frmtracking.cboTo14.DisplayMember = "UserName"
'To15
frmtracking.cboTo15.DataSource = dSet15.Tables("Users")
frmTracking.cboTo15.DisplayMember = "UserName"
'Auto Complete All the Fields
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To dTable.Tables(0).Rows.Count - 1
col.Add(dTable.Tables(0).Rows(i)("UserName").ToString.Trim())
frmTracking.cboTo1.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo1.AutoCompleteCustomSource = col
frmTracking.cboTo1.AutoCompleteMode = AutoCompleteMode.Suggest
Next
'Auto Complete All the Fields
Dim col2 As New AutoCompleteStringCollection
Dim ii As Integer
For ii = 0 To dSet2.Tables(0).Rows.Count - 1
col2.Add(dSet2.Tables(0).Rows(ii)("UserName").ToString.Trim())
frmTracking.cboTo2.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo2.AutoCompleteCustomSource = col2
frmTracking.cboTo2.AutoCompleteMode = AutoCompleteMode.Suggest
Next
'Auto Complete All the Fields
Dim col3 As New AutoCompleteStringCollection
Dim iii As Integer
For iii = 0 To dSet3.Tables(0).Rows.Count - 1
col3.Add(dSet3.Tables(0).Rows(iii)("UserName").ToString.Trim())
frmTracking.cboTo3.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo3.AutoCompleteCustomSource = col3
frmTracking.cboTo3.AutoCompleteMode = AutoCompleteMode.Suggest
Next
'Auto Complete All the Fields
Dim col4 As New AutoCompleteStringCollection
Dim iv As Integer
For iv = 0 To dSet4.Tables(0).Rows.Count - 1
col4.Add(dSet4.Tables(0).Rows(iv)("UserName").ToString.Trim())
frmTracking.cboTo4.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo4.AutoCompleteCustomSource = col4
frmTracking.cboTo4.AutoCompleteMode = AutoCompleteMode.Suggest
Next
'Auto Complete All the Fields
Dim col5 As New AutoCompleteStringCollection
Dim v As Integer
For v = 0 To dSet5.Tables(0).Rows.Count - 1
col5.Add(dSet5.Tables(0).Rows(v)("UserName").ToString.Trim())
frmTracking.cboTo5.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo5.AutoCompleteCustomSource = col5
frmTracking.cboTo5.AutoCompleteMode = AutoCompleteMode.Suggest
Next
Dim col6 As New AutoCompleteStringCollection
Dim vi As Integer
For vi = 0 To dSet6.Tables(0).Rows.Count - 1
col6.Add(dSet6.Tables(0).Rows(vi)("UserName").ToString.Trim())
frmTracking.cboTo6.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo6.AutoCompleteCustomSource = col6
frmTracking.cboTo6.AutoCompleteMode = AutoCompleteMode.Suggest
Next
Dim col7 As New AutoCompleteStringCollection
Dim vii As Integer
For vii = 0 To dSet7.Tables(0).Rows.Count - 1
col7.Add(dSet7.Tables(0).Rows(vii)("UserName").ToString.Trim())
frmTracking.cboTo7.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo7.AutoCompleteCustomSource = col7
frmTracking.cboTo7.AutoCompleteMode = AutoCompleteMode.Suggest
Next
Dim col8 As New AutoCompleteStringCollection
Dim viii As Integer
For viii = 0 To dSet8.Tables(0).Rows.Count - 1
col8.Add(dSet8.Tables(0).Rows(viii)("UserName").ToString.Trim())
frmTracking.cboTo8.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo8.AutoCompleteCustomSource = col8
frmTracking.cboTo8.AutoCompleteMode = AutoCompleteMode.Suggest
Next
Dim col9 As New AutoCompleteStringCollection
Dim ix As Integer
For ix = 0 To dSet9.Tables(0).Rows.Count - 1
col9.Add(dSet9.Tables(0).Rows(ix)("UserName").ToString.Trim())
frmTracking.cboTo9.AutoCompleteSource = AutoCompleteSource.CustomSource
frmTracking.cboTo9.AutoCompleteCustomSource = col9
frmTracking.cboTo9.AutoCompleteMode = AutoCompleteMode.Suggest
Next