<small id='wUelz'></small><noframes id='wUelz'>

  1. <i id='wUelz'><tr id='wUelz'><dt id='wUelz'><q id='wUelz'><span id='wUelz'><b id='wUelz'><form id='wUelz'><ins id='wUelz'></ins><ul id='wUelz'></ul><sub id='wUelz'></sub></form><legend id='wUelz'></legend><bdo id='wUelz'><pre id='wUelz'><center id='wUelz'></center></pre></bdo></b><th id='wUelz'></th></span></q></dt></tr></i><div id='wUelz'><tfoot id='wUelz'></tfoot><dl id='wUelz'><fieldset id='wUelz'></fieldset></dl></div>

      <bdo id='wUelz'></bdo><ul id='wUelz'></ul>
      <tfoot id='wUelz'></tfoot>

      <legend id='wUelz'><style id='wUelz'><dir id='wUelz'><q id='wUelz'></q></dir></style></legend>

      带有用户名数据的 AutoCompleteCustomSource 不起作用

      AutoCompleteCustomSource with user names data isn#39;t working(带有用户名数据的 AutoCompleteCustomSource 不起作用)

          <small id='rTnGM'></small><noframes id='rTnGM'>

            <tbody id='rTnGM'></tbody>

            <tfoot id='rTnGM'></tfoot>
            <legend id='rTnGM'><style id='rTnGM'><dir id='rTnGM'><q id='rTnGM'></q></dir></style></legend>

              • <bdo id='rTnGM'></bdo><ul id='rTnGM'></ul>
                <i id='rTnGM'><tr id='rTnGM'><dt id='rTnGM'><q id='rTnGM'><span id='rTnGM'><b id='rTnGM'><form id='rTnGM'><ins id='rTnGM'></ins><ul id='rTnGM'></ul><sub id='rTnGM'></sub></form><legend id='rTnGM'></legend><bdo id='rTnGM'><pre id='rTnGM'><center id='rTnGM'></center></pre></bdo></b><th id='rTnGM'></th></span></q></dt></tr></i><div id='rTnGM'><tfoot id='rTnGM'></tfoot><dl id='rTnGM'><fieldset id='rTnGM'></fieldset></dl></div>
                本文介绍了带有用户名数据的 AutoCompleteCustomSource 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试创建一个具有自动完成功能的文本框.
                在表单的构造函数中,我从数据库中获取数据并将 TextBox AutoCompleteCustomSource 属性设置为用户名数组.
                由于某种原因,自动完成功能无法正常工作.

                我确信 db.getUsersList() 方法没有问题(截图在底部).

                public mainPanel(){初始化组件();AutoCompleteStringCollection 集合 = 新 AutoCompleteStringCollection();集合.AddRange(db.getUserList().ToArray());nickName.AutoCompleteCustomSource = 集合;}

                解决方案

                要设置支持自动完成的控件,需要指定自动完成功能的来源.当使用

                私有类 NickName{公共字符串尼克 { 得到;放;}公共 int 值 { 获取;放;}}私有 BindingSource 源 = null;私人名单<昵称>昵称 = null;私人无效Form1_Load(对象发送者,EventArgs e){昵称 = 新列表<昵称>();NickNames.AddRange(new[] {新的 NickName() { Nick = "", Value = 0 },新的 NickName() { Nick = "Andrea", Value = 10 },新的 NickName() { Nick = "Arnold", Value = 20 },新的 NickName() { Nick = "Barbara", Value = 30 },新的 NickName() { Nick = "Billy", Value = 40 },新的 NickName() { Nick = "Clint", Value = 50 },新的 NickName() { Nick = "Cindy", Value = 60 },});源 = 新的 BindingSource();source.DataSource = 昵称;txtAutoComp.AutoCompleteMode = AutoCompleteMode.Suggest;txtAutoComp.AutoCompleteSource = AutoCompleteSource.CustomSource;txtAutoComp.AutoCompleteCustomSource.AddRange(NickNames.Select(n => n.Nick).ToArray());绑定 textBind = new Binding("Text", source, "Nick", true, DataSourceUpdateMode.OnPropertyChanged);textBind.Parse += (s, evt) =>{source.CurrencyManager.Position = NickNames.FindIndex(1, r => r.Nick.Equals(evt.Value));};txtAutoComp.DataBindings.Add(textBind);lblNickName.DataBindings.Add(new Binding("Text", source, "Nick"));lblNickValue.DataBindings.Add(new Binding("Text", source, "Value"));}私人无效btnFindNick_Click(对象发送者,EventArgs e){FindNick(txtAutoComp.Text);}私人无效txtAutoComp_KeyDown(对象发送者,KeyEventArgs e){if (e.KeyCode == Keys.Enter) {e.SuppressKeyPress = true;FindNick(txtAutoComp.Text);}}无效 FindNick(字符串部分名称)=>this.source.CurrencyManager.Position = NickNames.FindIndex(1, r =>r.Nick.Contains(partialName));

                I am trying to create a TextBox with auto completion.
                In the constructor of my Form, I am getting data from a database and set the TextBox AutoCompleteCustomSource property to the user names array.
                For some reason, the autocomplete feature is not working.

                I am sure that there are no problems with the db.getUsersList() method (screenshot at the bottom).

                public mainPanel()
                {
                    InitializeComponent();
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(db.getUserList().ToArray());
                    nickName.AutoCompleteCustomSource = collection;
                }
                

                解决方案

                To setup a control that supports auto completion, it's necessary to specify the source of the AutoComplete feature. When set to a string collection using the AutoCompleteCustomSource property, the AutoCompleteSource property must be set to AutoCompleteSource.CustomSource and AutoCompleteMode set to either AutoCompleteMode.SuggestAppend or AutoCompleteMode.Suggest.

                These properties must be used together to specify how the AutoComplete feature works.

                Since it appears the code in the question is using some sort of data source to create the AutoCompleteCustomSource collection, here's a generic example that creates a CustomSource from a List<class>, adds bindings to the controls using a Binding class and updates the values of some controls using a BindingSource.

                The example, as seen it visual sample, uses three control: a TextBox (txtAutoComp), where the AutoComplete feature is enabled, and two Labels (lblNickName and lblNickValue), bound to the same data source, which are updated when the text of AutoComple control changes.
                The AutoComplete is expanded to allow to find elements using partial strings, either clicking a Button (btnFindNick, here) or pressing the Enter key in the TextBox:

                private class NickName
                {
                    public string Nick { get; set; }
                    public int Value { get; set; }
                }
                
                private BindingSource source = null;
                private List<NickName> NickNames = null;
                
                private void Form1_Load(object sender, EventArgs e)
                {
                    NickNames = new List<NickName>();
                    NickNames.AddRange(new[] {
                        new NickName() { Nick = "", Value = 0 },
                        new NickName() { Nick = "Andrea", Value = 10 },
                        new NickName() { Nick = "Arnold", Value = 20 },
                        new NickName() { Nick = "Barbara", Value = 30 },
                        new NickName() { Nick = "Billy", Value = 40 },
                        new NickName() { Nick = "Clint", Value = 50 },
                        new NickName() { Nick = "Cindy", Value = 60 },
                    });
                    source = new BindingSource();
                    source.DataSource = NickNames;
                
                    txtAutoComp.AutoCompleteMode = AutoCompleteMode.Suggest;
                    txtAutoComp.AutoCompleteSource = AutoCompleteSource.CustomSource;
                    txtAutoComp.AutoCompleteCustomSource.AddRange(NickNames.Select(n => n.Nick).ToArray());
                
                    Binding textBind = new Binding("Text", source, "Nick", true, DataSourceUpdateMode.OnPropertyChanged);
                    textBind.Parse += (s, evt) => {
                        source.CurrencyManager.Position = NickNames.FindIndex(1, r => r.Nick.Equals(evt.Value));
                    };
                
                    txtAutoComp.DataBindings.Add(textBind);
                    lblNickName.DataBindings.Add(new Binding("Text", source, "Nick"));
                    lblNickValue.DataBindings.Add(new Binding("Text", source, "Value"));
                }
                
                private void btnFindNick_Click(object sender, EventArgs e)
                {
                    FindNick(txtAutoComp.Text);
                }
                
                private void txtAutoComp_KeyDown(object sender, KeyEventArgs e)
                {
                    if (e.KeyCode == Keys.Enter) {
                        e.SuppressKeyPress = true;
                        FindNick(txtAutoComp.Text);
                    }
                }
                
                void FindNick(string partialName) 
                    => this.source.CurrencyManager.Position = NickNames.FindIndex(
                        1, r => r.Nick.Contains(partialName)
                    );
                

                这篇关于带有用户名数据的 AutoCompleteCustomSource 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                Multi-color TextBox C#(多色文本框 C#)
                How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                <legend id='xN4Ca'><style id='xN4Ca'><dir id='xN4Ca'><q id='xN4Ca'></q></dir></style></legend>

                    <small id='xN4Ca'></small><noframes id='xN4Ca'>

                    <i id='xN4Ca'><tr id='xN4Ca'><dt id='xN4Ca'><q id='xN4Ca'><span id='xN4Ca'><b id='xN4Ca'><form id='xN4Ca'><ins id='xN4Ca'></ins><ul id='xN4Ca'></ul><sub id='xN4Ca'></sub></form><legend id='xN4Ca'></legend><bdo id='xN4Ca'><pre id='xN4Ca'><center id='xN4Ca'></center></pre></bdo></b><th id='xN4Ca'></th></span></q></dt></tr></i><div id='xN4Ca'><tfoot id='xN4Ca'></tfoot><dl id='xN4Ca'><fieldset id='xN4Ca'></fieldset></dl></div>
                      • <bdo id='xN4Ca'></bdo><ul id='xN4Ca'></ul>

                            <tbody id='xN4Ca'></tbody>
                          <tfoot id='xN4Ca'></tfoot>