A
AsherBeane
Guest
I'm working on a Visual basic assignment where the user is supposed to be able to add students to a club by selecting them form a list box and then they will be added to another list box there is also a drop down combo box where the user can select which club they are adding them to but if they change the selected club it will clear the list and allow them to add students to that club but If they should change back to a club they already added students to the selected list will already be there. this is what the form looks like
I cant figure out how to have the list of selected name be save so when the user selects a club again the they will all be there.
this is a full description of the assignment
www.chegg.com/homework-help/adding-students-clubs-programming-challenge-5-chapter-5-aske-chapter-8-problem-6pc-solution-9780134400150-exc
here is my code so far
Public Class Form1
Private strClubNames() As String = {"Honors", "Golden Arrow", "Computer", "Science"}
Private intEnrollSizes(strClubNames.Count) As Integer
Private strEnrollments(0, 0) As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each club As String In strClubNames
cboClubs.Items.Add(club)
Next
ReDim strEnrollments(strClubNames.Count, lstGeneral.Items.Count)
End Sub
Function CheckForInsertErrors() As Boolean
lblStatus.Text = String.Empty
If lstGeneral.SelectedIndex = -1 Then
lblStatus.Text = "Please select a name from the general student list"
Return False
End If
If cboClubs.SelectedIndex = -1 Then
lblStatus.Text = "Please select a club name from the list"
Return False
End If
Return True
End Function
Sub Clearmember()
Dim selected As String = lstMembers.SelectedItem.ToString
lstMembers.Items.Remove(selected)
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If Not CheckForInsertErrors() Then Return
Dim name As String = lstGeneral.SelectedItem.ToString()
Dim clubIndex As Integer = cboClubs.SelectedIndex
If Not lstMembers.Items.Contains(name) Then
lstMembers.Items.Add(name)
intEnrollSizes(clubIndex) += 1
lblCount.Text = lstMembers.Items.Count.ToString() & " members"
End If
'save the names back into the master array
For i = 0 To lstMembers.Items.Count - 1
strEnrollments(clubIndex, i) = lstMembers.Items(i).ToString
Next
End Sub
Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
Clearmember()
lblCount.Text = lstMembers.Items.Count.ToString() & " members"
End Sub
Private Sub cboClubs_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboClubs.SelectedIndexChanged
lstMembers.Items.Clear()
End Sub
End Class
Continue reading...
I cant figure out how to have the list of selected name be save so when the user selects a club again the they will all be there.
this is a full description of the assignment
www.chegg.com/homework-help/adding-students-clubs-programming-challenge-5-chapter-5-aske-chapter-8-problem-6pc-solution-9780134400150-exc
here is my code so far
Public Class Form1
Private strClubNames() As String = {"Honors", "Golden Arrow", "Computer", "Science"}
Private intEnrollSizes(strClubNames.Count) As Integer
Private strEnrollments(0, 0) As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each club As String In strClubNames
cboClubs.Items.Add(club)
Next
ReDim strEnrollments(strClubNames.Count, lstGeneral.Items.Count)
End Sub
Function CheckForInsertErrors() As Boolean
lblStatus.Text = String.Empty
If lstGeneral.SelectedIndex = -1 Then
lblStatus.Text = "Please select a name from the general student list"
Return False
End If
If cboClubs.SelectedIndex = -1 Then
lblStatus.Text = "Please select a club name from the list"
Return False
End If
Return True
End Function
Sub Clearmember()
Dim selected As String = lstMembers.SelectedItem.ToString
lstMembers.Items.Remove(selected)
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If Not CheckForInsertErrors() Then Return
Dim name As String = lstGeneral.SelectedItem.ToString()
Dim clubIndex As Integer = cboClubs.SelectedIndex
If Not lstMembers.Items.Contains(name) Then
lstMembers.Items.Add(name)
intEnrollSizes(clubIndex) += 1
lblCount.Text = lstMembers.Items.Count.ToString() & " members"
End If
'save the names back into the master array
For i = 0 To lstMembers.Items.Count - 1
strEnrollments(clubIndex, i) = lstMembers.Items(i).ToString
Next
End Sub
Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
Clearmember()
lblCount.Text = lstMembers.Items.Count.ToString() & " members"
End Sub
Private Sub cboClubs_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboClubs.SelectedIndexChanged
lstMembers.Items.Clear()
End Sub
End Class
Continue reading...