Home > Back-end >  Hide Checkbox of Parent/Specific Node in Treeview
Hide Checkbox of Parent/Specific Node in Treeview

Time:07-04

so i have a Form with a Treeview and i want it too look like this (I stole this Picture from another Post enter image description here

I googled and found nothing for Powershell but C# so i tried to adopt it but i am just not good enough.

here the Post i found

what i have so fare is as follows

$tvCRSC_DrawNode=[System.Windows.Forms.DrawTreeNodeEventHandler]{

if ($_.Node.Level -eq 1)
{
    $_.DrawDefault = $true
}
else
{
    $Format = [System.Drawing.StringFormat]::GenericDefault
    $Brush = New-Object Drawing.SolidBrush([System.Drawing.Color]::FromArgb(255, 255, 255, 255))
    $_.Graphics.DrawString($_.Node.Text,$_.Node.TreeView.Font,$Brush, $_.Node.Bounds.X, $_.Node.Bounds.Y, $Format)
}
}

But with that i get a treeview where the Node where i want no Checkpoint is just blank

  • Blank
    • [CB]ChildNode
    • [CB]ChildNode
  • Blank
    • [CB]ChildNode

as for the link.. i do not realy understand why they hide the Checkbox for the level 1 node or why there is a function needed at all..

I just want to draw the Level 0 Node myself without a CB but all i get is the Blank. Maybe someone can help me to understand and adopt the C# to Powershell.

Best Regards

CodePudding user response:

Sometimes you just do not look far enough. The Answer was in the Post i linked in the Question. Right here

i just had to edit it in the Function... had to replace any [Marshal] into [System.Runtime.InteropServices.Marshal]

it now works like a charm.

  • Related