Benutzer mit den meisten Antworten
TriState-TreeView

Frage
Antworten
-
Hallo Jörg,
das "hübsche" Gelb findet sich in den Ressourcen im Checked Icon.
Am einfachsten dürfte man es loswerden in dem man das Indeterminded Icon nimmt und den Haken in einem Malprogramm dunkler macht (mit GIMP über Kurven eine Sache von Sekunden).
Blöderweise hat der Autor den Zugriff auf die intern verwendete ImageList1 blockiert, in dem er die Klasse mit dem Attribut <DesignerCategory("Code")> versehen hat. Dokumentiert man es (temporär) aus, so kann man das Steuerelement im Designer öffnen und das Icon in der ImageList1 Image Auflistung gegen das geänderte austauschen.
Gruß Elmar- Als Antwort markiert Joerg 55 Dienstag, 20. September 2016 19:29
Alle Antworten
-
Hallo Joerg,
für welche Technologie (WPF, WinForms, ...) suchst du ein Control und was genau meinst du mit TriState?
Tom Lambert - .NET (C#) MVP
Wozu Antworten markieren und für Beiträge abstimmen? Klicke hier.
Nützliche Links: .NET Quellcode | C# ↔ VB.NET Konverter | Account bestätigen (Verify Your Account)
Ich: Webseite | Code Beispiele | Facebook | Twitter | Snippets -
Da du ja ein "aktuelles" Control suchst, kommen diese hier nicht in Frage:
http://www.codeproject.com/Articles/202435/Tri-State-Tree-View
http://www.codeproject.com/Articles/59514/Simple-Tri-State-TreeView
http://www.codeproject.com/Articles/6549/Tri-State-TreeView-Control
??
Vielleicht kannst du noch kurz preisgeben, ob du etwas für WinForms oder WPF suchst, sonst wird's schwer mit einem Tipp..
Gruß
-
Ja sorry, ich suche den TreeView für Windows.Forms.
Die von dir angesprochenen Links hatte ich mir schon angeschaut. Sie sind in C bzw. C# geschrieben, womit ich leider nicht allzuviel anfangen kann. Darüber hinaus habe ich bei dem Versuch, die Source-Codes zu kompilieren, auch diverse Fehlermeldungen erhalten.
Da ich mich wie gesagt in C nicht wirklich auskenne, wollte ich jetzt auch nicht von Stöckchen auf Hölzchen kommen, sondern möglichst ein für VB funktionierendes (oder ein in VB einbindbares) Control verwenden.
Gruß Joerg
- Bearbeitet Joerg 55 Dienstag, 20. September 2016 13:51
-
Hallo Jörg,
auch für Visual Basic findet sich auf Code Project etwas (-> filtern kann man in der Liste auf die gewünschte Sprache, Framework Version usw. klickt).
Ansonsten kann man auch eine C# Lösung verwenden, so sie gefällt, in dem man sie als Bibliothek einbindet (schließlich verwendest Du das .NET Framework, was zu großen Teilen in C# geschrieben ist ;))
Gruß Elmar
-
Hi, ich habe einfach den Source aus dem 1. Link meines vorherigen Posts genommen und nach vb.net konvertiert.
' Copyright (CPOL) 2011 RikTheVeggie - see http://www.codeproject.com/info/cpol10.aspx ' Tri-State Tree View http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=202435 ' <summary> ' A Tri-State TreeView designed for on-demand populating of the tree ' </summary> ' <remarks> ' 'Mixed' nodes retain their checked state, meaning they can be checked or unchecked according to their current state ' Tree can be navigated by keyboard (cursor keys & space) ' No need to do anything special in calling code ' </remarks> Public Class TriStateTreeView Inherits System.Windows.Forms.TreeView ' <remarks> ' CheckedState is an enum of all allowable nodes states ' </remarks> Public Enum CheckedState As Integer UnInitialised = -1 UnChecked Checked Mixed End Enum ' <remarks> ' IgnoreClickAction is used to ingore messages generated by setting the node.Checked flag in code ' Do not set <c>e.Cancel = true</c> in <c>OnBeforeCheck</c> otherwise the Checked state will be lost ' </remarks> Private IgnoreClickAction As Integer = 0 ' <remarks> ' TriStateStyles is an enum of all allowable tree styles ' All styles check children when parent is checked ' Installer automatically checks parent if all children are checked, and unchecks parent if at least one child is unchecked ' Standard never changes the checked status of a parent ' </remarks> Public Enum TriStateStyles As Integer Standard = 0 Installer End Enum ' Create a private member for the tree style, and allow it to be set on the property sheer Private TriStateStyle As TriStateStyles = TriStateStyles.Standard <System.ComponentModel.Category("Tri-State Tree View")> <System.ComponentModel.DisplayName("Style")> <System.ComponentModel.Description("Style of the Tri-State Tree View")> Public Property TriStateStyleProperty() As TriStateStyles Get Return TriStateStyle End Get Set TriStateStyle = Value End Set End Property ' <summary> ' Constructor. Create and populate an image list ' </summary> Public Sub New() MyBase.New() StateImageList = New System.Windows.Forms.ImageList() ' populate the image list, using images from the System.Windows.Forms.CheckBoxRenderer class For i As Integer = 0 To 2 ' Create a bitmap which holds the relevent check box style ' see http://msdn.microsoft.com/en-us/library/ms404307.aspx and http://msdn.microsoft.com/en-us/library/system.windows.forms.checkboxrenderer.aspx Dim bmp As New System.Drawing.Bitmap(16, 16) Dim chkGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp) Select Case i ' 0,1 - offset the checkbox slightly so it positions in the correct place Case 0 System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(chkGraphics, New System.Drawing.Point(0, 1), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal) Exit Select Case 1 System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(chkGraphics, New System.Drawing.Point(0, 1), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal) Exit Select Case 2 System.Windows.Forms.CheckBoxRenderer.DrawCheckBox(chkGraphics, New System.Drawing.Point(0, 1), System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal) Exit Select End Select StateImageList.Images.Add(bmp) Next End Sub ' <summary> ' Called once before window displayed. Disables default Checkbox functionality and ensures all nodes display an 'unchecked' image. ' </summary> Protected Overrides Sub OnCreateControl() MyBase.OnCreateControl() CheckBoxes = False ' Disable default CheckBox functionality if it's been enabled ' Give every node an initial 'unchecked' image IgnoreClickAction += 1 ' we're making changes to the tree, ignore any other change requests UpdateChildState(Me.Nodes, CInt(CheckedState.UnChecked), False, True) IgnoreClickAction -= 1 End Sub ' <summary> ' Called after a node is checked. Forces all children to inherit current state, and notifies parents they may need to become 'mixed' ' </summary> Protected Overrides Sub OnAfterCheck(e As System.Windows.Forms.TreeViewEventArgs) MyBase.OnAfterCheck(e) If IgnoreClickAction > 0 Then Return End If IgnoreClickAction += 1 ' we're making changes to the tree, ignore any other change requests ' the checked state has already been changed, we just need to update the state index ' node is either ticked or unticked. ignore mixed state, as the node is still only ticked or unticked regardless of state of children Dim tn As System.Windows.Forms.TreeNode = e.Node tn.StateImageIndex = If(tn.Checked, CInt(CheckedState.Checked), CInt(CheckedState.UnChecked)) ' force all children to inherit the same state as the current node UpdateChildState(e.Node.Nodes, e.Node.StateImageIndex, e.Node.Checked, False) ' populate state up the tree, possibly resulting in parents with mixed state UpdateParentState(e.Node.Parent) IgnoreClickAction -= 1 End Sub ' <summary> ' Called after a node is expanded. Ensures any new nodes display an 'unchecked' image ' </summary> Protected Overrides Sub OnAfterExpand(e As System.Windows.Forms.TreeViewEventArgs) ' If any child node is new, give it the same check state as the current node ' So if current node is ticked, child nodes will also be ticked MyBase.OnAfterExpand(e) IgnoreClickAction += 1 ' we're making changes to the tree, ignore any other change requests UpdateChildState(e.Node.Nodes, e.Node.StateImageIndex, e.Node.Checked, True) IgnoreClickAction -= 1 End Sub ' <summary> ' Helper function to replace child state with that of the parent ' </summary> Protected Sub UpdateChildState(Nodes As System.Windows.Forms.TreeNodeCollection, StateImageIndex As Integer, Checked As Boolean, ChangeUninitialisedNodesOnly As Boolean) For Each tnChild As System.Windows.Forms.TreeNode In Nodes If Not ChangeUninitialisedNodesOnly OrElse tnChild.StateImageIndex = -1 Then tnChild.StateImageIndex = StateImageIndex tnChild.Checked = Checked ' override 'checked' state of child with that of parent If tnChild.Nodes.Count > 0 Then UpdateChildState(tnChild.Nodes, StateImageIndex, Checked, ChangeUninitialisedNodesOnly) End If End If Next End Sub ' <summary> ' Helper function to notify parent it may need to use 'mixed' state ' </summary> Protected Sub UpdateParentState(tn As System.Windows.Forms.TreeNode) ' Node needs to check all of it's children to see if any of them are ticked or mixed If tn Is Nothing Then Return End If Dim OrigStateImageIndex As Integer = tn.StateImageIndex Dim UnCheckedNodes As Integer = 0, CheckedNodes As Integer = 0, MixedNodes As Integer = 0 ' The parent needs to know how many of it's children are Checked or Mixed For Each tnChild As System.Windows.Forms.TreeNode In tn.Nodes If tnChild.StateImageIndex = CInt(CheckedState.Checked) Then CheckedNodes += 1 ElseIf tnChild.StateImageIndex = CInt(CheckedState.Mixed) Then MixedNodes += 1 Exit For Else UnCheckedNodes += 1 End If Next If TriStateStyle = TriStateStyles.Installer Then ' In Installer mode, if all child nodes are checked then parent is checked ' If at least one child is unchecked, then parent is unchecked If MixedNodes = 0 Then If UnCheckedNodes = 0 Then ' all children are checked, so parent must be checked tn.Checked = True Else ' at least one child is unchecked, so parent must be unchecked tn.Checked = False End If End If End If ' Determine the parent's new Image State If MixedNodes > 0 Then ' at least one child is mixed, so parent must be mixed tn.StateImageIndex = CInt(CheckedState.Mixed) ElseIf CheckedNodes > 0 AndAlso UnCheckedNodes = 0 Then ' all children are checked If tn.Checked Then tn.StateImageIndex = CInt(CheckedState.Checked) Else tn.StateImageIndex = CInt(CheckedState.Mixed) End If ElseIf CheckedNodes > 0 Then ' some children are checked, the rest are unchecked tn.StateImageIndex = CInt(CheckedState.Mixed) Else ' all children are unchecked If tn.Checked Then tn.StateImageIndex = CInt(CheckedState.Mixed) Else tn.StateImageIndex = CInt(CheckedState.UnChecked) End If End If If OrigStateImageIndex <> tn.StateImageIndex AndAlso tn.Parent IsNot Nothing Then ' Parent's state has changed, notify the parent's parent UpdateParentState(tn.Parent) End If End Sub ' <summary> ' Called on keypress. Used to change node state when Space key is pressed ' Invokes OnAfterCheck to do the real work ' </summary> Protected Overrides Sub OnKeyDown(e As System.Windows.Forms.KeyEventArgs) MyBase.OnKeyDown(e) ' is the keypress a space? If not, discard it If e.KeyCode = System.Windows.Forms.Keys.Space Then ' toggle the node's checked status. This will then fire OnAfterCheck SelectedNode.Checked = Not SelectedNode.Checked End If End Sub ' <summary> ' Called when node is clicked by the mouse. Does nothing unless the image was clicked ' Invokes OnAfterCheck to do the real work ' </summary> Protected Overrides Sub OnNodeMouseClick(e As System.Windows.Forms.TreeNodeMouseClickEventArgs) MyBase.OnNodeMouseClick(e) ' is the click on the checkbox? If not, discard it Dim info As System.Windows.Forms.TreeViewHitTestInfo = HitTest(e.X, e.Y) If info Is Nothing OrElse info.Location <> System.Windows.Forms.TreeViewHitTestLocations.StateImage Then Return End If ' toggle the node's checked status. This will then fire OnAfterCheck Dim tn As System.Windows.Forms.TreeNode = e.Node tn.Checked = Not tn.Checked End Sub End Class
Konverter gibt's im Netz reichlich...
-
Hi Elmar,
dank dir erstmal für deine Mühe. Dieses Control hatte ich mir auch schon angeschaut. Man kann den Source-Code ja auch direkt in VB runterladen. Eigentlich tut dieses TreeView schon ziemlich genau, was ich möchte. Aber ... nicht auslachen bitte ;-) wie kriege ich diese häßliche gelbe Checked-Häkchen weg????
Ich hatte ein neues Icon mit weißem Hintergrund erstellt, die Checked.ico-Ressource in ImageList2 ausgetauscht und das Projekt neu erstellt. Die Checkbox bleibt aber mit gelbem Hintergrund. WARUM in aller Welt??? Ich finde auch die Stelle, an der dieses Gelb-Icon der Checkbox als Image zugewiesen wird nicht. Das müßte doch irgendwo im Designer passieren?
Hast du einen Tipp, wie ich das Image für den Checkbox-Zustand 'Checked' auf den Standardwert von Windows zurücksetzen kann?
Gruß Joerg
- Bearbeitet Joerg 55 Dienstag, 20. September 2016 16:14
-
Hallo Jörg,
das "hübsche" Gelb findet sich in den Ressourcen im Checked Icon.
Am einfachsten dürfte man es loswerden in dem man das Indeterminded Icon nimmt und den Haken in einem Malprogramm dunkler macht (mit GIMP über Kurven eine Sache von Sekunden).
Blöderweise hat der Autor den Zugriff auf die intern verwendete ImageList1 blockiert, in dem er die Klasse mit dem Attribut <DesignerCategory("Code")> versehen hat. Dokumentiert man es (temporär) aus, so kann man das Steuerelement im Designer öffnen und das Icon in der ImageList1 Image Auflistung gegen das geänderte austauschen.
Gruß Elmar- Als Antwort markiert Joerg 55 Dienstag, 20. September 2016 19:29
-
Hi Elmar,
du kommst in mein Nachtgebet. Da wäre ich im Leben nicht drauf gekommen.
Ist das hier die Zeile, in der das so ausgetauschte Icon 'eingelesen' wird?
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Sie steht ganz am Ende von 'ThreestateTreeview.vb' in #Region "Designergenerated".
Denn dort ist mit 'Friend WithEvents ImageList1 As ImageList ja nochmal ein 'ImageList1' definiert. Dort hatte ich immer gesucht.
Gruß Joerg
- Bearbeitet Joerg 55 Dienstag, 20. September 2016 19:53