【问题标题】:Winforms control that works like ajax tag-completionWinforms 控件的工作方式类似于 ajax 标记完成
【发布时间】:2010-03-10 09:12:57
【问题描述】:

我想创建一个 winforms 应用程序,您可以在其中将标签分配给实体。 ofc 我希望客户大量重复使用现有标签。这就是我想要的原因 在他们输入时向他们显示标签列表(类似于智能感知 在 VS 和标签下拉列表中,甚至在 stackoverflow 中;))

  • 您是否有任何提供此功能的控件?
  • 我可以为此重复使用 ComboBox 吗? (在这里我需要以编程方式将其删除 - 如何?)

我想让 taglist 获得 input-focus 但又不会失去 mainform-focus, 我希望它位于所有窗口之上,甚至超出主窗体区域 (就像 vs 中的智能感知)

谢谢!

【问题讨论】:

    标签: c# .net winforms combobox tagging


    【解决方案1】:

    在这里,我创建了一个函数,用于传递需要自动完成的表名、需要自动完成的字段名称以及需要定位的组合框。

    试试下面的代码:

    public void AutoCompleteTextBox(string tableName, string fieldName, ComboBox combToAutoComp)
            {
                AutoCompleteStringCollection txtCollection = new AutoCompleteStringCollection();
                DataTable dtAutoComp = Dal.ExecuteDataSetBySelect("Stored_Procedure", fieldName, tableName);
                if (dtAutoComp.Rows.Count >= 0)
                {
                    for (int count = 0; count < dtAutoComp.Rows.Count; count++)
                    {
                        txtCollection.Add(dtAutoComp.Rows[count][fieldName].ToString());
                    }
                }
                combToAutoComp.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                combToAutoComp.AutoCompleteSource = AutoCompleteSource.CustomSource;
                combToAutoComp.AutoCompleteCustomSource = txtCollection;
            }
    

    这里Dal.ExecuteDataSetBySelect 是我的实现,我在其中创建用于调用存储过程的连接、命令和数据适配器。您可以将其替换为您自己的实现。更多请参考this link

    【讨论】:

    • 谢谢哥们,工作得很好。尽管经过更多的努力,我决定采用 WPF 的更陡峭的学习曲线,并使用 WPF 从头开始​​我的项目 - 祝我好运:)
    猜你喜欢
    • 1970-01-01
    • 2010-10-05
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    相关资源
    最近更新 更多