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
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
Comment