无法跳出数据绑定Winforms下拉列表 [英] Cannot tab out of databound Winforms dropdown list

查看:54
本文介绍了无法跳出数据绑定Winforms下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有点奇怪,但是我已经挣扎了几个小时,我不知道发生了什么。

This is a bit of a strange one, but I've been struggling for a few hours now and I can't understand what is happening.

我当时想知道是否有人遇到过这个问题,也许可以解释一下。我正在构建一个简单的Winforms应用,并尝试使用许多内置控件。

I was wondering if anyone else has experienced this problem, and can perhaps explain it. I'm building a simple Winforms app and trying to use many of the built in controls.

基本上,我有一个带有用户控件和一些数据捕获字段的表单。其中的3个字段是下拉列表,在用户控件上,我有一个bindingSource控件直接绑定到Product类。

Basically, I've got a form with a user control and some data capture fields. 3 of the fields are dropdown lists and on the user control I have a bindingSource control that binds directly to a Product class.

在运行时,我提供了Product的实例BindingSource类,并且该类包含 ProductType 属性。为简单起见,我还向产品类添加了 List< ProductType> 产品类型,该类在查询时会自动加载,这意味着我可以使用相同的bindingSource并选择 ProductTypes 数据成员作为下拉列表的数据源。

At run time I provide an instance of the Product class to the BindingSource and the class contains a property of ProductType. For simplicity I also added a List<ProductType> ProductTypes to the Product Class which loads itself when queried, which means I can just use the same bindingSource and choose the ProductTypes Data Member as the Datasource for the dropdownlist.

运行表单后,该列表将完美绑定,我可以看到所有产品列出的类型,我可以选择一个和选项卡,或单击到下一个字段。但显然所选值不会绑定,因为我没有为下拉列表选择任何bindings-SelectedValue,而是仅选择了一个数据源。只要确保下拉列表通过绑定到Bindings-SelectedValue来修改Product的实例,然后运行该表单,该列表仍会完美填充,并且只要我不选择,就可以通过控件进行切换从下拉列表中进行选择。如果我从下拉列表中进行选择,则下拉列表保持焦点。我无法选择出爱情或金钱,甚至无法点击表单上的取消按钮,右上角的关闭按钮是我唯一可以点击的按钮,我无法点击其他任何字段或下拉菜单。一旦选择,这会影响所有三个下拉菜单。

Upon running the form, the list binds perfectly and I can see all the product types listed, and I can select one and tab or click to the next field. But obviously the selected value won't bind because I've not chosen any bindings-SelectedValue for the dropdown, only a datasource. As soon as I make sure that the drop down modifies the instance of the Product by binding to the Bindings-SelectedValue, and then run the form, the list still gets populated perfectly and I can tab through the controls as long as I don't make a selection from the dropdown. If I make a selection from the dropdown then the dropdown holds focus. I cannot tab out for love or money and can't even click cancel button on the form, the close button top right is the only button I can click which works and I can't click any other field or dropdown. This affects all three dropdowns as soon as a selection is made.

任何人都知道我缺少什么吗?

Anyone have any ideas what I'm missing?

我尝试更改一些内容,并通过将下拉值输入字符串[]而不是对象的成员来取得了一些成功。似乎可行,但是击败使用数据绑定的对象不是吗?

I have tried changing a few things and had some success by feeding the dropdown values a string[] instead of a member of an object. That seems to work, but defeats the object of using databinding doesn't it?

任何帮助表示赞赏!

推荐答案

在这里只是猜测,因为我现在没有时间设置测试并进行确认,但是您正在进行任何验证吗?我似乎记得,如果内容未经验证,数据绑定控件将不允许您离开。即使您未明确表示,也可以尝试将CausesValidation设置为False,以查看幕后是否有任何形式的验证,这至少可以为您提供提示。

Just guessing here, because I don't have time to set up a test and confirm right now, but are you doing any validating? I seem to remember that data-bound controls won't let you leave if the contents don't validate. Even if you aren't explicitly, try setting CausesValidation to False to see if there's any sort of validation going on behind the scenes, that might at least give you a hint.

这篇关于无法跳出数据绑定Winforms下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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