【发布时间】:2023-03-21 03:54:01
【问题描述】:
我有一个表单上有一个数字字段的 winforms 应用程序。这开始为空,然后如果我将其设置为数字,更改焦点然后再次清除文本框更改回之前输入的数字。如果我更改号码,例如。从 4 到 5 已正确更新,但我希望用户能够清除已输入的内容。
以下是一些演示此行为的示例代码:
public partial class Form1 : Form
{
DataTable table = new DataTable("TableName");
public Form1()
{
DataColumn column = new DataColumn("NumericColumnName", typeof(Double));
column.AllowDBNull = true;
table.Columns.Add(column);
object[] rowData = new object[1];
rowData[0] = DBNull.Value;
table.Rows.Add(rowData);
InitializeComponent();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = table;
Binding binding = new Binding("Text", bindingSource, "NumericColumnName");
textBox1.DataBindings.Add(binding);
}
}
这是在 Visual Studio 2008 中一个全新的 .net 3.5 表单项目中。我在表单中添加了两个文本框。
我的实际应用程序以不同方式生成数据集,但它具有相同的行为。绑定到数据表的数字列是否允许空值。
【问题讨论】:
-
能否在您检查/显示文本框值的位置插入处理程序的代码?谢谢
-
没有处理程序 - 请参阅我更新的帖子我创建了一个简单的表单 winforms 应用程序来演示问题。
标签: c# .net winforms .net-3.5 binding