C# 保存文本框自动完成CustomeSource
所以,我有以下几点C# 保存文本框自动完成CustomeSource,c#,winforms,C#,Winforms,所以,我有以下几点 textBox1.Text = Properties.Settings.Default.NetworkIP; AutoCompleteStringCollection sc = Properties.Settings.Default.IPList; textBox1.AutoCompleteCustomSource = sc; 和 和 NetworkIP的保存/恢复工作正常。 保存和还原IPList工作正常。 小问题。 编辑t
textBox1.Text = Properties.Settings.Default.NetworkIP;
AutoCompleteStringCollection sc = Properties.Settings.Default.IPList;
textBox1.AutoCompleteCustomSource = sc;
和
和
NetworkIP的保存/恢复工作正常。
保存和还原IPList工作正常。
小问题。
编辑textBox1后按Enter或TAB键,只会在突出显示textBox1的内容中重新调整大小,光标位于末尾。我必须实际单击下一个字段才能移动光标
注释这个允许标签,但不进入工作正常,但当然我没有得到保存
AutoCompleteStringCollection sc = Properties.Settings.Default.IPList;
sc.Add(textBox1.Text);
Properties.Settings.Default.IPList = sc;
用户是什么,如何删除下拉列表中的条目
谢谢你的帮助
Ian此外,通过将设置类型更改为System.Windows.Forms.AutoCompleteTestringCollection,可以将自动完成条目存储为AutoCompleteTestringCollection
AutoCompleteStringCollection sc = Properties.Settings.Default.autoComp
textBox1.AutoCompleteCustomSource = sc;
sc.Add("new option")//or whatever you want
//set the setting
Properties.Settings.Default.autoComp;
//save it to file
Properties.Settings.Default.Save();
我有点困惑,如果您需要存储(IPList或更新的IPList),那么您是否有兴趣保存
Textbox
选择或AutoCompleteSource
,下面的代码片段可能有助于解决您的问题
AutoCompleteStringCollection source = textBox1.AutoCompleteCustomSource;
if (Properties.Settings.Default.IPLIST != null)
{
Properties.Settings.Default.IPLIST.Clear();
Properties.Settings.Default.IPLIST.AddRange(source.Cast<string>().ToArray());
Properties.Settings.Default.Save();
}
AutoCompleteStringCollection source=textBox1.AutoCompleteCustomSource;
if(Properties.Settings.Default.IPLIST!=null)
{
Properties.Settings.Default.IPLIST.Clear();
Properties.Settings.Default.IPLIST.AddRange(source.Cast().ToArray());
Properties.Settings.Default.Save();
}
您需要自己创建对象。。该类是AutoCompleteTestringCollection。关于msdn:HI Sean,这似乎是一种更简单的方法,但我似乎没有“System.Windows.Forms.AutoCompleteTestringCollection”用户设置。您使用的是什么开发环境?或者您是如何创建设置文件的。嗨,肖恩,Visual Studio 2015 C#。通过项目|属性|设置使用app.config设置。。我只是在学习VS&C。我使用相同的IDE。我发现这些说明很有效。按照前面的几个步骤来使用AutoCompleteTestringCollection.Hi Hari。无意冒犯。只是觉得肖恩的解决方案可能更容易实现。我假定您的例程进入textBox1_-Leave?此逻辑是否进入textBox1_-Leave
或任何其他事件取决于具体实现。
AutoCompleteStringCollection sc = Properties.Settings.Default.autoComp
textBox1.AutoCompleteCustomSource = sc;
sc.Add("new option")//or whatever you want
//set the setting
Properties.Settings.Default.autoComp;
//save it to file
Properties.Settings.Default.Save();
AutoCompleteStringCollection source = textBox1.AutoCompleteCustomSource;
if (Properties.Settings.Default.IPLIST != null)
{
Properties.Settings.Default.IPLIST.Clear();
Properties.Settings.Default.IPLIST.AddRange(source.Cast<string>().ToArray());
Properties.Settings.Default.Save();
}