格式化和高级绑定窗口和空值 [英] Formatting and Advanced Binding Window and Null Values

查看:52
本文介绍了格式化和高级绑定窗口和空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击"控件属性"窗口 - > DataBindings-> Advanced
时出现的弹出窗口允许您设置控件用于显示DBNull值的值。不幸的是,如果将此窗口的"空值"字段留空,则在后台生成的绑定的DBNull属性将设置为null。如何使用UI将"Null Value"字段设置为空字符串(不是手动更改代码中的绑定)?

The popup window that comes up when you click on the
Control Properties Window->DataBindings->Advanced
allows you to set the value that the control uses to display a DBNull value. Unfortunately, if you leave the 'Null value' field of this window blank, the DBNull property for the binding generated behind the scenes is set to null. How do you set the 'Null Value' field to an empty string using the UI (not manually changing the binding in your code)?

推荐答案

我将尝试回答为什么会这样。

I'm going to attempt an answer as to why it's like that.

在此"空值"中字段,您有机会输入一些文本,让用户知道该字段实际上为空(或DBNull)。

In this "null value" field, you are given a chance to enter some text to let the user know that this field is actually null (or DBNull).

这"空值" string实际上并不存储在DataSource中,而是在Binding类的Format事件期间写入Control。

This "null value" string is not actually stored in the DataSource, but rather it is written to the Control during the Format event of the Binding class.

现在,我并不认为为这个字段设置string.Empty值会有任何好处,因为它会使TextBox保持空白(这里使用TextBox作为示例),这已经通过保留"null值"来实现。字段空白。

Now, I don't really think there would be any advantage putting an string.Empty value for this field, as it would leave the TextBox blank anyway (using TextBox as an example here), which is already accomplished by leaving the "null value" field blank.

另一方面,如果您考虑在数据源级别拥有默认值,那么您应该小心在那个级别,而不是UI级别。例如,您可以在DataSet设计器中为该特定列指定NullValue。或者你甚至可以(取决于你的数据库服务器)为该列指定一个默认值,这样它就永远不会为空。

On the other hand, if you were thinking of having a default value at the data source level, then you should take care of it at that level, not the UI level. You could, for example, specify a NullValue in the DataSet designer for that particular column. Or you could even (depending on your database server) specify a default value for that column so that it's never actually null.

也许你有想要这个的特定用例?如果是这样,你能给我们更多细节吗?

Maybe you have a specific use-case for wanting this ? If so, could you give us a bit more detail ?

问候,

Luc


这篇关于格式化和高级绑定窗口和空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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