Populating of list delayed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lotus18
    Contributor
    • Nov 2007
    • 865

    Populating of list delayed

    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.

    [CODE=vb .net]
    Private Sub cboCourses_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cboCourses.Clic k
    CourseID = GetCourseID("Se lect * From Courses Where Title='" & cboCourses.Text & "'")
    Sections.Show(D ataSections, CommandSections , CourseID, lvwSections, LinkRefresh)
    End Sub

    'Sections----------------------------------------------
    Public Sub Show(ByVal adDataReader As OleDbDataReader , ByVal adCommand As _
    OleDbCommand, ByVal ID As String, ByVal adList As ListView, ByVal adShowStatus _
    As LinkLabel)
    Windows.Forms.C ursor.Current = Cursors.WaitCur sor

    SQLString = "Select * From Sections Where CourseID='" & ID & "' Order By " & _
    "Title ASC"

    Call Main.SetConnect ion()
    adCommand = New OleDbCommand(SQ LString, dbConnection)
    adCommand.Comma ndType = CommandType.Tex t
    adDataReader = adCommand.Execu teReader

    adList.Items.Cl ear()
    While adDataReader.Re ad
    adItem = adList.Items.Ad d(adDataReader( 0), 0) 'Section ID
    adItem.SubItems .Add(adDataRead er(1)) 'Section
    End While

    If adList.Items.Co unt > 0 Then
    adShowStatus.Vi sible = False
    frmSections.btn Delete.Enabled = True
    'frmSections.bt nUpdate.Enabled = True
    frmSections.btn Print.Enabled = True
    Else
    adShowStatus.Vi sible = True
    frmSections.btn Delete.Enabled = False
    'frmSections.bt nUpdate.Enabled = False
    frmSections.btn Print.Enabled = False
    End If

    For i = 0 To adList.Items.Co unt - 1
    If i Mod 2 = 0 Then
    adList.Items(i) .BackColor = Color.White
    Else
    adList.Items(i) .BackColor = Color.AliceBlue
    End If
    Next i

    adDataReader.Cl ose()
    Call Main.CloseConne ction()
    Windows.Forms.C ursor.Current = Cursors.Default
    End Sub
    '----------------------------------------------------------
    Friend Function GetCourseID(ByV al SQLQuery As String) As String
    Call Main.SetConnect ion()

    adCommand = New OleDbCommand(SQ LQuery, dbConnection)
    adCommand.Comma ndType = CommandType.Tex t
    adDataReader = adCommand.Execu teReader
    adDataReader.Re ad()
    GetCourseID = adDataReader(0)

    adDataReader.Cl ose()
    Main.CloseConne ction()
    End Function
    [/CODE]

    Rey Sean
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    You should not fill a combo box on its click event.
    It should fill in form load or previous control events.

    Comment

    • daniel aristidou
      Contributor
      • Aug 2007
      • 494

      #3
      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

      Comment

      • lotus18
        Contributor
        • Nov 2007
        • 865

        #4
        Originally posted by CyberSoftHari
        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.

        Originally posted by daniel aristidou
        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

        Comment

        • CyberSoftHari
          Recognized Expert Contributor
          • Sep 2007
          • 488

          #5
          Thanks to point me lotus, then you have to use indexchanged as daniel aristidou said.

          Comment

          Working...