属性网格:自动完成组合框? [英] Property Grids: AutoComplete ComboBox?

查看:69
本文介绍了属性网格:自动完成组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过从StringConverter派生在PropertyGrid中创建下拉列表.我也知道,如果我对GetStandardValuesExclusive()的覆盖返回True,则该下拉列表实际上是一个简单的下拉列表,您不能键入它,只能从中选择.如果返回False,则可以键入,但现在将不再验证.

我的问题是,是否有一种简单的方法可以强制PropertyGrid中的下拉列表强制(A)自动完成,并且(B)将条目限制为列表(验证条目)?

I know how to create dropdowns in a PropertyGrid by deriving from StringConverter. I also know that if my override of GetStandardValuesExclusive() returns True, then the dropdown is in fact a simple dropdown and you can't type into it but only select from it. If it returns False, you can type into it but now it will no longer validate.

My question is, is there an easy way to force the dropdown inside the PropertyGrid to (A) autocomplete and (B) limit the entry to the list (validate the entry)?

推荐答案

对不起,答复在游戏中太晚了,因此对您来说可能没有用,但是您的问题的答案是是"和是".

我来了通过以下解决方案,我对组合框进行了一些更改,它将需要进行一些修改,但是如果您仍然遇到问题,则可能会适合您的情况:

我要感谢我来了解以下线程的解决方案:
http://social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/c22f1d6d-b6d8-4a40-a497-987c4fdac82e

/> XAML:

Sorry the response is so late in the game, so it may be of no use to you, but the answer to your questions is Yes and Yes

I came up with the following solution where I changed the combobox around a little, it will require some modification, but might work for your situation if you still have the issue:

I'd like to give credit for getting me to the solution to the following thread:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c22f1d6d-b6d8-4a40-a497-987c4fdac82e

XAML:

<ComboBox Name="cmbCustomer" IsEditable="True" IsReadOnly="True" IsTextSearchEnabled="False"/>


C#:


C#:

        public SelectCustomer()
        {
            InitializeComponent();
            cmbCustomer.ItemsSource = LoadCustomerList();
            cmbCustomer.Loaded += new RoutedEventHandler(cmbCustomer_Loaded);
            cmbCustomer.DropDownClosed += new EventHandler(cmbCustomer_DropDownClosed);
        }

        void cmbCustomer_DropDownClosed(object sender , EventArgs e)
        {
            ///Clear the combobox if what the users types in is not in the list
            if (cmbCustomer.Text != "")
            {
                TextBox textBox = cmbCustomer.Template.FindName("PART_EditableTextBox" , cmbCustomer) as TextBox;

                if (!cmbCustomer.Items.Contains(textBox.Text))
                {
                    textBox.Clear();
                }
            }
        }

        private IList<string> LoadCustomerList()
        {
            ///get the list of customers from the database
            DataTable dt_Customer = AppMain.dataAccess.getApprovedCustomers();
            List<string> customers = new List<string>();

            foreach (DataRow dr in dt_Customer.Rows)
            {
                customers.Add(dr["Customers"].ToString());
            }

            return customers;
        }

        void cmbCustomer_Loaded(object sender , RoutedEventArgs e)
        {
            ///only necessary if the FindName statement bellow returns null
            cmbCustomer.ApplyTemplate();

            TextBox textBox = cmbCustomer.Template.FindName("PART_EditableTextBox" , cmbCustomer) as TextBox;
            textBox.IsReadOnly = false;

            if (textBox != null)
            {
                textBox.TextChanged += delegate
                {
                    ///open the drop down and start filtering based on what the user types into the combobox
                    cmbCustomer.IsDropDownOpen = true;
                    cmbCustomer.Items.Filter += a =>
                    {
                        if (a.ToString().ToUpper().Contains(textBox.Text.ToUpper()))
                            return true;
                        else
                            return false;
                    }
                }
            }
        }


这篇关于属性网格:自动完成组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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