Skip to content

Commit

Permalink
Improve supported product filter tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleex255 committed Jun 25, 2021
1 parent a8a5bf9 commit a328253
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PolicyPlus/FilterOptions.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 31 additions & 5 deletions PolicyPlus/FilterOptions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
Next
AlwaysMatchAnyCheckbox.Checked = Configuration.AlwaysMatchAny
MatchBlankSupportCheckbox.Checked = Configuration.MatchBlankSupport
' Expand to show all products with a different check state than their parent
Dim expandIfNecessary As Action(Of TreeNode)
expandIfNecessary = Sub(Node As TreeNode)
For Each subnode As TreeNode In Node.Nodes
expandIfNecessary(subnode)
If subnode.IsExpanded Or subnode.Checked <> Node.Checked Then
Node.Expand()
End If
Next
End Sub
For Each node As TreeNode In AllowedProductsTreeview.Nodes
expandIfNecessary(node)
Next
End If
End Sub
Private Sub SupportedCheckbox_CheckedChanged(sender As Object, e As EventArgs) Handles SupportedCheckbox.CheckedChanged
Expand Down Expand Up @@ -110,11 +123,15 @@
AllowedProductsTreeview.BackColor = If(AllowedProductsTreeview.Enabled, SystemColors.Window, SystemColors.Control)
End Sub
Private Sub AllowedProductsTreeview_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles AllowedProductsTreeview.AfterCheck
If e.Node.Checked Then
For Each subnode As TreeNode In e.Node.Nodes
subnode.Checked = True
Next
End If
' Recursively set the check state on child products only in response to the user
If e.Action = TreeViewAction.Unknown Then Return
PropogateCheckStateDown(e.Node)
End Sub
Sub PropogateCheckStateDown(Node As TreeNode)
For Each subnode As TreeNode In Node.Nodes
subnode.Checked = Node.Checked
PropogateCheckStateDown(subnode)
Next
End Sub
End Class
Public Enum FilterPolicyState
Expand All @@ -130,4 +147,13 @@ Public Class FilterConfiguration
Public AllowedProducts As List(Of PolicyPlusProduct)
Public AlwaysMatchAny As Boolean
Public MatchBlankSupport As Boolean
End Class
' The TreeView control has a bug: the displayed check state gets out of sync with the Checked property when the checkbox is double-clicked
' Fix adapted from https://stackoverflow.com/a/3174824
Friend Class DoubleClickIgnoringTreeView
Inherits TreeView
Protected Overrides Sub WndProc(ByRef m As Message)
' Ignore WM_LBUTTONDBLCLK
If m.Msg <> &H203 Then MyBase.WndProc(m)
End Sub
End Class

0 comments on commit a328253

Please sign in to comment.