问题描述
我已经填充了一些项目到使用DataSource属性列表框。现在,我需要设置AutoCompleteCustomSource从列表框中列出的项目一个文本框。 precisely,数据源的列表框和AutoCompleteCustomSource对TextBox相同。我怎样才能设置AutoCompleteCustomSource不使用for循环?
NET 2.0只。没有对LINQ的支持
I have populated some items into a listbox using the datasource property. Now I need to set the AutoCompleteCustomSource for a textBox from the items listed in the listbox. Precisely, the DataSource for the ListBox and the AutoCompleteCustomSource for the textBox are same. How can I set the AutoCompleteCustomSource without using the for-loops?
.Net 2.0 only. No support for LINQ
推荐答案
在 AutoCompleteStringCollection
只需的String []
,所以它应该是这样的:
The AutoCompleteStringCollection
takes only string[]
, so it should be like this:
var cc = new AutoCompleteStringCollection();
cc.AddRange(listBox1.Items.Cast<string>().ToArray());
这篇关于ListBox中的项目,如AutoCompleteCustomSource一个TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!