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

Populating of list delayed

lotus18
100+
P: 866
Hello World

I have this code almost same with my previous project and it works well. Actually, I'm converting my previous project in vb6 to vb .net.

Now, here's my problem, I need to click twice the cboCourses to populate the list. What I want is everytime I click (or select an item) on a combobox it must populate the list immediately without clicking it twice.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub cboCourses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCourses.Click
  2.         CourseID = GetCourseID("Select * From Courses Where Title='" & cboCourses.Text & "'")
  3.         Sections.Show(DataSections, CommandSections, CourseID, lvwSections, LinkRefresh)
  4.     End Sub
  5.  
  6. 'Sections----------------------------------------------
  7. Public Sub Show(ByVal adDataReader As OleDbDataReader, ByVal adCommand As _
  8.     OleDbCommand, ByVal ID As String, ByVal adList As ListView, ByVal adShowStatus _
  9.     As LinkLabel)
  10.         Windows.Forms.Cursor.Current = Cursors.WaitCursor
  11.  
  12.         SQLString = "Select * From Sections Where CourseID='" & ID & "' Order By " & _
  13.         "Title ASC"
  14.  
  15.         Call Main.SetConnection()
  16.         adCommand = New OleDbCommand(SQLString, dbConnection)
  17.         adCommand.CommandType = CommandType.Text
  18.         adDataReader = adCommand.ExecuteReader
  19.  
  20.         adList.Items.Clear()
  21.         While adDataReader.Read
  22.             adItem = adList.Items.Add(adDataReader(0), 0)       'Section ID
  23.             adItem.SubItems.Add(adDataReader(1))                'Section
  24.         End While
  25.  
  26.         If adList.Items.Count > 0 Then
  27.             adShowStatus.Visible = False
  28.             frmSections.btnDelete.Enabled = True
  29.             'frmSections.btnUpdate.Enabled = True
  30.             frmSections.btnPrint.Enabled = True
  31.         Else
  32.             adShowStatus.Visible = True
  33.             frmSections.btnDelete.Enabled = False
  34.             'frmSections.btnUpdate.Enabled = False
  35.             frmSections.btnPrint.Enabled = False
  36.         End If
  37.  
  38.         For i = 0 To adList.Items.Count - 1
  39.             If i Mod 2 = 0 Then
  40.                 adList.Items(i).BackColor = Color.White
  41.             Else
  42.                 adList.Items(i).BackColor = Color.AliceBlue
  43.             End If
  44.         Next i
  45.  
  46.         adDataReader.Close()
  47.         Call Main.CloseConnection()
  48.         Windows.Forms.Cursor.Current = Cursors.Default
  49.     End Sub
  50. '----------------------------------------------------------
  51. Friend Function GetCourseID(ByVal SQLQuery As String) As String
  52.         Call Main.SetConnection()
  53.  
  54.         adCommand = New OleDbCommand(SQLQuery, dbConnection)
  55.         adCommand.CommandType = CommandType.Text
  56.         adDataReader = adCommand.ExecuteReader
  57.         adDataReader.Read()
  58.         GetCourseID = adDataReader(0)
  59.  
  60.         adDataReader.Close()
  61.         Main.CloseConnection()
  62.     End Function
  63.  
Rey Sean
May 31 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 487
You should not fill a combo box on its click event.
It should fill in form load or previous control events.
May 31 '08 #2

daniel aristidou
100+
P: 491
hi lotus.
use the indexchanged eventinstead of the click event
Dont worry.i took me a long time to figure out how to do stuff in .net as well.....just needs a bit of exploring
May 31 '08 #3

lotus18
100+
P: 866
You should not fill a combo box on its click event.
It should fill in form load or previous control events.
If you just noticed my codes, It doesn't fill a combo box. It fills an items on a listview based on the items that you selected in a combobox.

use the indexchanged eventinstead of the click event
Dont worry.i took me a long time to figure out how to do stuff in .net as well.....just needs a bit of exploring
OK, Daniel I'll try it later. Thanks! : )

Rey Sean
May 31 '08 #4

Expert 100+
P: 487
Thanks to point me lotus, then you have to use indexchanged as daniel aristidou said.
Jun 1 '08 #5

Post your reply

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