1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| ''' <summary>Function updating dropdown lists of comboboxs inside specified container(s).
''' The function will update only comboboxs whose name contains their associated DataTable's name.
''' The user can add personalized filtering parameters.</summary>
''' <param name="flpanel1">1st group of comboboxs, necessary, As FlowLayoutPanel</param>
''' <param name="flpanel2">2nd group of comboboxs, optional, As FlowLayoutPanel</param>
''' <param name="flpanel3">3rd group of comboboxs, optional, As FlowLayoutPanel</param>
''' <param name="Setup">Number designating which Setup belongs the comboboxs to be reseted, value As String, optional, accepted values = "", "1" or "2"</param>
''' <param name="RowFilter">Additional filtering parameters, optional, as String</param>
''' <remarks>The function will keep current text values in comboboxs if they already match the filter expression.</remarks>
Private Sub UpdateEquipList(ByVal flpanel1 As FlowLayoutPanel, Optional ByVal flpanel2 As FlowLayoutPanel = Nothing, Optional ByVal flpanel3 As FlowLayoutPanel = Nothing, Optional ByVal Setup As String = "", Optional ByVal RowFilter As String = "")
Dim OriginalRowFilter As String = RowFilter
Dim MutualExCbxName, MutualExCbxText As String
Dim NeededDataTables As String() = {"Food", "Weapon", "Ranged", "Ammo", "Head", "Neck", "Ear", "Ring", "Hands", "Body", "Legs", "Feet", "Waist", "Back", "WStable"}
If Not {"", "1", "2"}.Contains(Setup) OrElse flpanel1 Is Nothing Then Exit Sub
'Contains datatables from the Dataset, whose names appears in NeededDataTables
Dim DataTablesToUse As _
IEnumerable(Of DataTable) = (From dt As Object In Me.DataSet.Tables _
Where NeededDataTables.Contains(DirectCast(dt, DataTable).TableName) _
Select DirectCast(dt, DataTable))
'Searches inside specified container(s) for controls of type combobox,
'Then builds a filtered collection with each row containing associated Datatable|Container|Combobox
Dim CbxEtDtALier = (From dt As DataTable In DataTablesToUse _
From flp As FlowLayoutPanel In New FlowLayoutPanel() {flpanel1, flpanel2, flpanel3} _
Where flp IsNot Nothing _
From c As ComboBox In flp.Controls.OfType(Of ComboBox)() _
Where c.Name.Contains(dt.TableName) AndAlso (c.Name.Contains(Setup) OrElse Setup = "") _
Select New With {.dtble = dt, .flp = flp, .cbx = c})
For Each element In CbxEtDtALier
MutualExCbxName = ""
Select Case element.cbx.Name ' All different pairs of mutually exclusive comboboxs
Case "MainWeapon1"
MutualExCbxName = "SubWeapon1"
Case "SubWeapon1"
MutualExCbxName = "MainWeapon1"
Case "LeftEarTP1"
MutualExCbxName = "RightEarTP1"
Case "RightEarTP1"
MutualExCbxName = "LeftEarTP1"
Case "LeftRingTP1"
MutualExCbxName = "RightRingTP1"
Case "RightRingTP1"
MutualExCbxName = "LeftRingTP1"
Case "LeftEarWS1"
MutualExCbxName = "RightEarWS1"
Case "RightEarWS1"
MutualExCbxName = "LeftEarWS1"
Case "LeftRingWS1"
MutualExCbxName = "RightRingWS1"
Case "RightRingWS1"
MutualExCbxName = "LeftRingWS1"
Case "MainWeapon2"
MutualExCbxName = "SubWeapon2"
Case "SubWeapon2"
MutualExCbxName = "MainWeapon2"
Case "LeftEarTP2"
MutualExCbxName = "RightEarTP2"
Case "RightEarTP2"
MutualExCbxName = "LeftEarTP2"
Case "LeftRingTP2"
MutualExCbxName = "RightRingTP2"
Case "RightRingTP2"
MutualExCbxName = "LeftRingTP2"
Case "LeftEarWS2"
MutualExCbxName = "RightEarWS2"
Case "RightEarWS2"
MutualExCbxName = "LeftEarWS2"
Case "LeftRingWS2"
MutualExCbxName = "RightRingWS2"
Case "RightRingWS2"
MutualExCbxName = "LeftRingWS2"
Case Else
End Select
If MutualExCbxName <> "" Then
MutualExCbxText = element.flp.Controls.Item(MutualExCbxName).Text
If MutualExCbxText <> "" Then
With element.dtble.Rows.Find(MutualExCbxText)
'Checking if the text of next Mutual Exclusive combobox will be reset or not when will be its turn. If yes, no RowFilter, otherwise filter it out this combobox's list.
If MutualExCbxName.StartsWith("Sub|Right") OrElse (.Item("Equippable Jobs").ToString.Contains(Me.MainJob1.Text & "|ALL") AndAlso CInt(.Item("Level").ToString) <= Me.MainLevel1.Value) Then
RowFilter = RowFilter & "AND NOT( Names = '" & Replace(MutualExCbxText, "'", "''") & "' AND [Rare Tag] = 'True' )"
End If
End With
End If
End If
Dim dv As New DataView(element.dtble)
dv.RowFilter = RowFilter
dv.RowStateFilter = DataViewRowState.CurrentRows
dv.ApplyDefaultSort = True
element.cbx.DataSource = dv
element.cbx.DisplayMember = "Names"
If element.cbx.Tag Is Nothing Then : element.cbx.Tag = "" : End If
If dv.Find(element.cbx.Tag.ToString) > -1 Then
element.cbx.Text = element.cbx.Tag.ToString
Else
element.cbx.ResetText()
element.cbx.Tag = ""
End If
RowFilter = OriginalRowFilter
Next
End Sub |
Partager