我有一個窗體上的數字字段的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);
}
}
這是一個全新的.NET 3.5的形式項目在Visual Studio 2008中我添加了兩個文本框的形式。
我的實際應用程序以不同的方式生成數據集,但它具有相同的行爲。綁定到數據表的數字列允許空值。
你能插入處理程序的代碼,你檢查/顯示文本框的值嗎? thx – swissben 2011-03-10 13:13:30
沒有處理程序 - 請參閱我的更新後的帖子我創建了一個簡單的表單winforms應用程序來演示問題。 – 2011-03-10 13:41:03