Hi Jorgen,
Thank you for writing.
To properly restore the items you need to recreate the same data source and assign it to the autocomplete box. The following example shows how you can save and restore the items using simple csv file. The
MyItem class just contains two properties (text and value). The code adds all the items to the autocomplete box when the data source is restored. This is achieved with the
Text property:
private
void
radButton1_Click(
object
sender, EventArgs e)
{
selctedItems = radAutoCompleteBox1.Text;
var csv =
new
StringBuilder();
foreach
(var item
in
(BindingList<MyItem>) radAutoCompleteBox1.AutoCompleteDataSource)
{
var first = item.Text.ToString();
var second = item.Value.ToString();
var newLine =
string
.Format(
"{0},{1}{2}"
, first, second, Environment.NewLine);
csv.Append(newLine);
}
File.WriteAllText(
"test.csv"
, csv.ToString());
}
private
void
radButton2_Click(
object
sender, EventArgs e)
{
BindingList<MyItem> data =
new
BindingList<MyItem>();
string
text =
""
;
var reader =
new
StreamReader(File.OpenRead(@
"test.csv"
));
while
(!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(
','
);
data.Add(
new
MyItem()
{
Text = values[0],
Value =
int
.Parse(values[1])
});
text += values[0] +
";"
;
}
radAutoCompleteBox1.AutoCompleteDataSource = data;
radAutoCompleteBox1.AutoCompleteDisplayMember =
"Text"
;
radAutoCompleteBox1.AutoCompleteValueMember =
"Value"
;
radAutoCompleteBox1.Text = text;
}
Could you please check the above code and see if it is suitable for your case? If not could you please specify how this approach is different from your real one?
I am looking forward to your reply.
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items