Autocomplete text and additions

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.
Locked
User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Autocomplete text and additions

Post by jimbobukii » Wed Apr 03, 2013 9:19 am

I have been looking at the textbox auto complet function, very good.

A simple form:
PowerShell Code
Double-click the code block to select all.
$form1_Load={
	#TODO: Initialize Form Controls here
	$list = Get-Content "c:\list.txt"
}

$textbox1_TextChanged={
	#TODO: Place custom script here
	$textbox1.AutoCompleteCustomSource.AddRange($list)
}

$button1_Click={
	#TODO: Place custom script here
	#[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][System.Windows.Forms.MessageBox]::Show("Selected = $($textbox1.Text)","")
}
What I would like to do is if an item is not in the list, when I click button1 it is added to $list(file) and the msgbox is then presented again
It does not add if it already exists so std append is no good

What I would also like is $list to be displayed as is. ie. $list contains:
  • One
    Two
    Three
using
PowerShell Code
Double-click the code block to select all.
$textbox1.AutoCompleteCustomSource.AddRange($list)
The list is sorted alphabetically

Any help?

Thanks in advance

User avatar
davidc
Posts: 5889
Joined: Thu Aug 18, 2011 4:56 am

Re: Autocomplete text and additions

Post by davidc » Wed Apr 03, 2013 9:55 am

I'm not sure I quite understand what you want.

If you want to display the complete list, then I recommend using the ComboBox control instead. You ComboBox can also sort the items.

If you want to add to a new item to the list then do the following:
PowerShell Code
Double-click the code block to select all.
$button1_Click={
	#TODO: Place custom script here
	$textbox1.AutoCompleteCustomSource.Add($textbox1.Text)
}
You might want to check if the text isn't already in the list before doing so.

David
David
SAPIEN Technologies, Inc.

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Autocomplete text and additions

Post by jimbobukii » Thu Apr 04, 2013 12:22 am

Thanks helped perfectly

I was wondering how to refresh the textbox so if any new lines were added to the file they would appear in the text box custom source without having to exit the form?

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Autocomplete text and additions

Post by jimbobukii » Thu Apr 04, 2013 12:23 am

its ok I worked this out :)

Locked