学生管理系统(优化篇二)

一、在优化设置年级课程窗体的时候遇到一个问题:点击设置课程在listALLcourse控件里面会出现添加的课程,但是再点击一次会重复出现多次,效果如下图所示:
解决思路:
在listAllcourse里面加入判断语句,先检查列表框的内容是否重复,如果重复则显示已添加课程,负责在listselectcourse列表中添加课程。单击一下添加课程按钮显示所有课程,然后该按钮不可用。
代码展示:
Dim selectcourse As Integer
    Dim i As Integer
    Dim j As Integer
If ListSelectcourse.List(i) = ListSelectcourse.List(j) Then
         ListSelectcourse.RemoveItem j
          MsgBox "已添加此课程!", vbOKOnly + vbExclamation, "提示"
    Exit Sub
    End If
       Next j
    Next i
End If
结果如下图所示
二、在经过师傅的提醒中间的两个选择按钮是不是可以不需要呢,在经过百度和尝试之后实现了这个功能。
代码展示
Private Sub ListAllcourse_DblClick()
    Dim selectcourse As Integer
    Dim i As Integer
    Dim j As Integer
    
    For selectcourse = 0 To ListAllcourse.ListCount - 1
    If ListAllcourse.Selected(selectcourse) = True Then
       ListSelectcourse.AddItem ListAllcourse.List(ListAllcourse.ListIndex)
       
    '添加课程
    For i = 0 To ListSelectcourse.ListCount - 1

       For j = i + 1 To ListSelectcourse.ListCount
    '判断列表框中内容是否重复
    If ListSelectcourse.List(i) = ListSelectcourse.List(j) Then
         ListSelectcourse.RemoveItem j
          MsgBox "已添加此课程!", vbOKOnly + vbExclamation, "提示"
    Exit Sub
    End If
       Next j
    Next i
   End If
   Next selectcourse
    If ListAllcourse.ListIndex <> -1 Then
             ListSelectcourse.ListIndex = -1
         End If
End Sub

Private Sub ListSelectcourse_Click()
'    If ListSelectcourse.ListIndex <> -1 Then
'          ListAllcourse.ListIndex = -1
'      End If
End Sub
Private Sub combograde_KeyPress(KeyAscii As Integer)
If KeyAscii > 0 Then
     KeyAscii = 0
       MsgBox "请选择下拉菜单!", vbOKCancel, "警告"
       End If
       ComboGrade.Text = ""
End Sub

Private Sub ListSelectcourse_DblClick()
    '判断是否有内容被选中
    If ListSelectcourse.ListIndex <> -1 Then
        'ListSelectcourse.RemoveItem ListAllcourse.ListIndex
         ListSelectcourse.RemoveItem ListSelectcourse.ListIndex
    End If

End Sub

问题解决啦!

猜你喜欢

转载自blog.csdn.net/damishidai15/article/details/80395076
今日推荐