我有一个代码,它是过滤器的一种,显示根据组合框的选定索引显示的元素。我正在使用“选择案例”方法,但似乎该方法不足以应用。
如果autoMBS.tlbCheckBodyCompCtrl_cmb_substrlvl.SelectedIndex=0
将什么也不做
如果autoMBS.tlbCheckBodyCompCtrl_cmb_substrlvl.SelectedIndex=1
仅显示第1组
如果autoMBS.tlbCheckBodyCompCtrl_cmb_substrlvl.SelectedIndex=2
将显示第1组+第2组
如果autoMBS.tlbCheckBodyCompCtrl_cmb_substrlvl.SelectedIndex=3
将显示第1组+第2组+第3组
正如您在下面的代码中看到的那样,代码中有很多重复项可以显示出来。
Public Shared Sub checkGetBodies(ByVal SpckModel As IScrModel, ByVal SpckClass As String)
Dim Bodies As IScrNamedObjectList
Bodies = SpckModel.getBodyList(False)
checkListBodies(Bodies, autoMBS.dgvCheckBodyComp, SpckClass)
autoMBS.tlbCheckBodyCompCtrl_cmb_filt.Items.Add(SpckClass)
If autoMBS.tlbCheckBodyCompCtrl_cmb_substr.SelectedIndex = 2 Then
Dim SubstrsLvL1 As IScrNamedObjectList
Dim SubstrLvL1 As IScrSubstructure
Dim nSubstrLvL1 As Integer
Dim SubstrsLvL2 As IScrNamedObjectList
Dim SubstrLvL2 As IScrSubstructure
Dim nSubstrLvL2 As Integer
Dim SubstrsLvL3 As IScrNamedObjectList
Dim SubstrLvL3 As IScrSubstructure
Dim nSubstrLvL3 As Integer
Select Case autoMBS.tlbCheckBodyCompCtrl_cmb_substrlvl.SelectedIndex
Case 0
Case 1
SubstrsLvL1 = SpckModel.getSubstrList(False)
nSubstrLvL1 = SubstrsLvL1.count
If nSubstrLvL1 > 0 Then
For x As Integer = 0 To nSubstrLvL1 - 1
SubstrLvL1 = SubstrsLvL1.item(x)
checkGetSubstrBodies(SubstrLvL1, SubstrLvL1.name)
Next
End If
Case 2
SubstrsLvL1 = SpckModel.getSubstrList(False)
nSubstrLvL1 = SubstrsLvL1.count
If nSubstrLvL1 > 0 Then
For x As Integer = 0 To nSubstrLvL1 - 1
SubstrLvL1 = SubstrsLvL1.item(x)
checkGetSubstrBodies(SubstrLvL1, SubstrLvL1.name)
SubstrsLvL2 = SubstrLvL1.getSubstrList(False)
nSubstrLvL2 = SubstrsLvL2.count
If nSubstrLvL2 > 0 Then
For y As Integer = 0 To nSubstrLvL2 - 1
SubstrLvL2 = SubstrsLvL2.item(y)
checkGetSubstrBodies(SubstrLvL2, SubstrLvL2.name)
Next
End If
Next
End If
Case 3
SubstrsLvL1 = SpckModel.getSubstrList(False)
nSubstrLvL1 = SubstrsLvL1.count
If nSubstrLvL1 > 0 Then
For x As Integer = 0 To nSubstrLvL1 - 1
SubstrLvL1 = SubstrsLvL1.item(x)
checkGetSubstrBodies(SubstrLvL1, SubstrLvL1.name)
SubstrsLvL2 = SubstrLvL1.getSubstrList(False)
nSubstrLvL2 = SubstrsLvL2.count
If nSubstrLvL2 > 0 Then
For y As Integer = 0 To nSubstrLvL2 - 1
SubstrLvL2 = SubstrsLvL2.item(y)
checkGetSubstrBodies(SubstrLvL2, SubstrLvL2.name)
SubstrsLvL3 = SubstrLvL2.getSubstrList(False)
nSubstrLvL3 = SubstrsLvL3.count
If nSubstrLvL3 > 0 Then
For z As Integer = 0 To nSubstrLvL3 - 1
SubstrLvL3 = SubstrsLvL3.item(z)
checkGetSubstrBodies(SubstrLvL3, SubstrLvL3.name)
Next
End If
Next
End If
Next
End If
End Select
End If
End Sub