By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

BindingSource with comboboxes using Autocomplete feature

P: 54
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.


Expand|Select|Wrap|Line Numbers
  1. 'Connection already established
  2. SQLCon.ConnectionString = DataL1
  3.         SqlQuery = "Select * from Users order by  UserName asc"
  4.         dSet1 = New DataSet : dSet2 = New DataSet : dSet3 = New DataSet : dSet4 = New DataSet
  5.         dSet5 = New DataSet : dSet6 = New DataSet : dSet7 = New DataSet : dSet8 = New DataSet
  6.         dSet9 = New DataSet : dSet10 = New DataSet : dSet11 = New DataSet : dSet12 = New DataSet
  7.         dSet13 = New DataSet : dSet14 = New DataSet : dSet15 = New DataSet
  8.         dTable = New DataSet
  9.         daAdapterRec = New SqlDataAdapter
  10.         daAdapter1 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter2 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter3 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter4 = New SqlDataAdapter(SqlQuery, SQLCon)
  11.         daAdapter5 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter6 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter7 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter8 = New SqlDataAdapter(SqlQuery, SQLCon)
  12.         daAdapter9 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter10 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter11 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter12 = New SqlDataAdapter(SqlQuery, SQLCon)
  13.         daAdapter13 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter14 = New SqlDataAdapter(SqlQuery, SQLCon) : daAdapter15 = New SqlDataAdapter(SqlQuery, SQLCon)
  14.         daAdapter = New SqlDataAdapter(SqlQuery, SQLCon)
  15.         Try
  16.             daAdapter1.Fill(dSet1, "Users") : daAdapter2.Fill(dSet2, "Users") : daAdapter3.Fill(dSet3, "Users") : daAdapter4.Fill(dSet4, "Users") : daAdapter5.Fill(dSet5, "Users") : daAdapter5.Fill(dSet5, "Users")
  17.             daAdapter6.Fill(dSet6, "Users") : daAdapter7.Fill(dSet7, "Users") : daAdapter8.Fill(dSet8, "Users") : daAdapter9.Fill(dSet9, "Users") : daAdapter10.Fill(dSet10, "Users") : daAdapter11.Fill(dSet11, "Users")
  18.             daAdapter12.Fill(dSet12, "Users") : daAdapter13.Fill(dSet13, "Users") : daAdapter14.Fill(dSet14, "Users") : daAdapter15.Fill(dSet15, "Users")
  19.             daAdapter.Fill(dTable, "Users")
  20.             'From1
  21.             frmtracking.cboFrom1.DataSource = dTable.Tables("Users")
  22.             frmtracking.cboFrom1.DisplayMember = "UserName"
  23.             frmTracking.cboFrom1.Text = frmVisibleNot.txtUsername.Text.Trim
  24.  
  25.             'To1
  26.             frmtracking.cboTo1.DataSource = dSet1.Tables("Users")
  27.             frmtracking.cboTo1.DisplayMember = "UserName"
  28.             'To2
  29.             frmtracking.cboTo2.DataSource = dSet2.Tables("Users")
  30.             frmtracking.cboTo2.DisplayMember = "UserName"
  31.             'To3
  32.             frmtracking.cboTo3.DataSource = dSet3.Tables("Users")
  33.             frmtracking.cboTo3.DisplayMember = "UserName"
  34.             'To4
  35.             frmtracking.cboTo4.DataSource = dSet4.Tables("Users")
  36.             frmtracking.cboTo4.DisplayMember = "UserName"
  37.             'To5
  38.             frmtracking.cboTo5.DataSource = dSet5.Tables("Users")
  39.             frmtracking.cboTo5.DisplayMember = "UserName"
  40.             'To6
  41.             frmtracking.cboTo6.DataSource = dSet6.Tables("Users")
  42.             frmtracking.cboTo6.DisplayMember = "UserName"
  43.             'To7
  44.             frmtracking.cboTo7.DataSource = dSet7.Tables("Users")
  45.             frmtracking.cboTo7.DisplayMember = "UserName"
  46.             'To8
  47.             frmtracking.cboTo8.DataSource = dSet8.Tables("Users")
  48.             frmtracking.cboTo8.DisplayMember = "UserName"
  49.             'To9
  50.             frmtracking.cboTo9.DataSource = dSet9.Tables("Users")
  51.             frmtracking.cboTo9.DisplayMember = "UserName"
  52.             'To10
  53.             frmtracking.cboTo10.DataSource = dSet10.Tables("Users")
  54.             frmtracking.cboTo10.DisplayMember = "UserName"
  55.             'To11
  56.             frmtracking.cboTo11.DataSource = dSet11.Tables("Users")
  57.             frmtracking.cboTo11.DisplayMember = "UserName"
  58.             'To12
  59.             frmtracking.cboTo12.DataSource = dSet12.Tables("Users")
  60.             frmtracking.cboTo12.DisplayMember = "UserName"
  61.             frmtracking.cboTo12.Text = ""
  62.             'To13
  63.             frmtracking.cboTo13.DataSource = dSet13.Tables("Users")
  64.             frmtracking.cboTo13.DisplayMember = "UserName"
  65.             'To14
  66.             frmtracking.cboTo14.DataSource = dSet14.Tables("Users")
  67.             frmtracking.cboTo14.DisplayMember = "UserName"
  68.             'To15
  69.             frmtracking.cboTo15.DataSource = dSet15.Tables("Users")
  70.             frmTracking.cboTo15.DisplayMember = "UserName"
  71.             'Auto Complete All the Fields
  72.             Dim col As New AutoCompleteStringCollection
  73.             Dim i As Integer
  74.             For i = 0 To dTable.Tables(0).Rows.Count - 1
  75.                 col.Add(dTable.Tables(0).Rows(i)("UserName").ToString.Trim())
  76.                 frmTracking.cboTo1.AutoCompleteSource = AutoCompleteSource.CustomSource
  77.                 frmTracking.cboTo1.AutoCompleteCustomSource = col
  78.                 frmTracking.cboTo1.AutoCompleteMode = AutoCompleteMode.Suggest
  79.             Next
  80.  
  81.             'Auto Complete All the Fields
  82.             Dim col2 As New AutoCompleteStringCollection
  83.             Dim ii As Integer
  84.             For ii = 0 To dSet2.Tables(0).Rows.Count - 1
  85.                 col2.Add(dSet2.Tables(0).Rows(ii)("UserName").ToString.Trim())
  86.                 frmTracking.cboTo2.AutoCompleteSource = AutoCompleteSource.CustomSource
  87.                 frmTracking.cboTo2.AutoCompleteCustomSource = col2
  88.                 frmTracking.cboTo2.AutoCompleteMode = AutoCompleteMode.Suggest
  89.             Next
  90.             'Auto Complete All the Fields
  91.             Dim col3 As New AutoCompleteStringCollection
  92.             Dim iii As Integer
  93.             For iii = 0 To dSet3.Tables(0).Rows.Count - 1
  94.                 col3.Add(dSet3.Tables(0).Rows(iii)("UserName").ToString.Trim())
  95.                 frmTracking.cboTo3.AutoCompleteSource = AutoCompleteSource.CustomSource
  96.                 frmTracking.cboTo3.AutoCompleteCustomSource = col3
  97.                 frmTracking.cboTo3.AutoCompleteMode = AutoCompleteMode.Suggest
  98.             Next
  99.             'Auto Complete All the Fields
  100.             Dim col4 As New AutoCompleteStringCollection
  101.             Dim iv As Integer
  102.             For iv = 0 To dSet4.Tables(0).Rows.Count - 1
  103.                 col4.Add(dSet4.Tables(0).Rows(iv)("UserName").ToString.Trim())
  104.                 frmTracking.cboTo4.AutoCompleteSource = AutoCompleteSource.CustomSource
  105.                 frmTracking.cboTo4.AutoCompleteCustomSource = col4
  106.                 frmTracking.cboTo4.AutoCompleteMode = AutoCompleteMode.Suggest
  107.             Next
  108.             'Auto Complete All the Fields
  109.             Dim col5 As New AutoCompleteStringCollection
  110.             Dim v As Integer
  111.             For v = 0 To dSet5.Tables(0).Rows.Count - 1
  112.                 col5.Add(dSet5.Tables(0).Rows(v)("UserName").ToString.Trim())
  113.                 frmTracking.cboTo5.AutoCompleteSource = AutoCompleteSource.CustomSource
  114.                 frmTracking.cboTo5.AutoCompleteCustomSource = col5
  115.                 frmTracking.cboTo5.AutoCompleteMode = AutoCompleteMode.Suggest
  116.             Next
  117.             Dim col6 As New AutoCompleteStringCollection
  118.             Dim vi As Integer
  119.             For vi = 0 To dSet6.Tables(0).Rows.Count - 1
  120.                 col6.Add(dSet6.Tables(0).Rows(vi)("UserName").ToString.Trim())
  121.                 frmTracking.cboTo6.AutoCompleteSource = AutoCompleteSource.CustomSource
  122.                 frmTracking.cboTo6.AutoCompleteCustomSource = col6
  123.                 frmTracking.cboTo6.AutoCompleteMode = AutoCompleteMode.Suggest
  124.             Next
  125.  
  126.  
  127.             Dim col7 As New AutoCompleteStringCollection
  128.             Dim vii As Integer
  129.             For vii = 0 To dSet7.Tables(0).Rows.Count - 1
  130.                 col7.Add(dSet7.Tables(0).Rows(vii)("UserName").ToString.Trim())
  131.                 frmTracking.cboTo7.AutoCompleteSource = AutoCompleteSource.CustomSource
  132.                 frmTracking.cboTo7.AutoCompleteCustomSource = col7
  133.                 frmTracking.cboTo7.AutoCompleteMode = AutoCompleteMode.Suggest
  134.             Next
  135.  
  136.             Dim col8 As New AutoCompleteStringCollection
  137.             Dim viii As Integer
  138.             For viii = 0 To dSet8.Tables(0).Rows.Count - 1
  139.                 col8.Add(dSet8.Tables(0).Rows(viii)("UserName").ToString.Trim())
  140.                 frmTracking.cboTo8.AutoCompleteSource = AutoCompleteSource.CustomSource
  141.                 frmTracking.cboTo8.AutoCompleteCustomSource = col8
  142.                 frmTracking.cboTo8.AutoCompleteMode = AutoCompleteMode.Suggest
  143.             Next
  144.  
  145.             Dim col9 As New AutoCompleteStringCollection
  146.             Dim ix As Integer
  147.             For ix = 0 To dSet9.Tables(0).Rows.Count - 1
  148.                 col9.Add(dSet9.Tables(0).Rows(ix)("UserName").ToString.Trim())
  149.                 frmTracking.cboTo9.AutoCompleteSource = AutoCompleteSource.CustomSource
  150.                 frmTracking.cboTo9.AutoCompleteCustomSource = col9
  151.                 frmTracking.cboTo9.AutoCompleteMode = AutoCompleteMode.Suggest
  152.             Next
  153.  
  154.  
Apr 23 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.