Save AutoCompleteCustomSource using My.Settings

Soldato
Joined
20 Jan 2005
Posts
2,722
Location
Whitley Bay
**VB.NET**

Hi there,

I wonder if anyone can help me:

I use a textbox AutoCompleteCustomSource to save recent entries within a textbox and obviously, then autocomplete them when the user enters a matching value. When the application is closed then re-opened these values are lost.

I believe I can save the values using My.Settings but I haven't been able to get it to work.

I created a setting 'AutoCompleteList' of type System.Windows.Forms.AutoCompleteStringCollection in the Project properties > Settings area.

This allows me to use the code below on the form's load event:
Code:
SearchBox.AutoCompleteCustomSource = My.Settings.AutoCompleteList

and the code below in the form closing event:
Code:
My.Settings.AutoCompleteList.Clear()
My.Settings.AutoCompleteList = SearchBox.AutoCompleteCustomSource

However nothing appears to be saved/loaded. Can anyone point out where I'm going wrong? New to the my.settings area.

Thanks

Si
:)

Edit: Just tested again and I'm actually getting 'Object reference not set to an instance of an object' for the line "My.Settings.AutoCompleteList.Clear()".
 
Last edited:
Back
Top Bottom