ListBox中的项目,如AutoCompleteCustomSource一个TextBox [英] ListBox items as AutoCompleteCustomSource for a textbox

查看:66
本文介绍了ListBox中的项目,如AutoCompleteCustomSource一个TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经填充了一些项目到使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆