Remove text from richtexbox (to use status of jobs)?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Remove text from richtexbox (to use status of jobs)?

Post by jvierra »

A simple way to do this is:
  1. $completed = {
  2.             Param($job)
  3.             $listbox1.Items.Remove($job.Name)
  4.     }
  5.     $myjobname = 'somejob'
  6.     Add-JobTracker -Name $myjobname ... -CompletedScript $completed
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Remove text from richtexbox (to use status of jobs)?

Post by stevens »

Thanks but never used a datasource for a listbox. Is there an example you could share?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Remove text from richtexbox (to use status of jobs)?

Post by jvierra »

To answer your basic question- if it helps - consider the following:
  1. #
  2.         $listview1.Items.Add('one','one',0)
  3.     $listview1.Items.Add('two', 'two', 0)
  4.     $listview1.Items.Add('three', 'three', 0)
  5.     $idx= $listview1.Items.IndexOfKey('two')
  6.     $listview1.Items.RemoveAt($idx)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Remove text from richtexbox (to use status of jobs)?

Post by jvierra »

I will also note that a richtest has a "Lines" property but it can only be editedd by a complete replacement ot "Lines"

$richtext.Lines = $richtext.Lines | ?{$_ -notmatch 'value'}
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Remove text from richtexbox (to use status of jobs)?

Post by stevens »

Would you mind explaining what your code is doing?
Why do you add three items and why is the idx needed?
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked