Page 1 of 1

Autocomplete text and additions

Posted: Wed Apr 03, 2013 9:19 am
by jimbobukii
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

Re: Autocomplete text and additions

Posted: Wed Apr 03, 2013 9:55 am
by davidc
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

Re: Autocomplete text and additions

Posted: Thu Apr 04, 2013 12:22 am
by jimbobukii
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?

Re: Autocomplete text and additions

Posted: Thu Apr 04, 2013 12:23 am
by jimbobukii
its ok I worked this out :)