2009-05-04 52 views
1

我在.Net 2.0中做了一些綁定。這是一個麻煩!我有一個DataTable(我試圖使用DataRow,但它沒有)和一個BindingNavigator(這似乎是神奇的成分)與BindingSource,我編程綁定到它的控制。不過,我的一個專欄是我肯定不想向用戶展示的ID,但我仍然需要隨時訪問。因爲我使用ID來對數據庫進行更多的調用,所以我希望在調用時調用它。數據綁定到我在.Net 2.0中創建的屬性

我的想法是在適當類型的表單代碼中創建自己的屬性,然後綁定到該屬性。這不起作用,即使使用相同的代碼綁定到文本框屬性。爲什麼不?

下面是一些代碼在我的用戶,所以你可以看到我在做什麼:

Guid SetID { get; set; } 

//... 

DataTable SetTable = DatabaseObject.GetDataTable(tablename) 
SetTable.DefaultView.Sort = "DisplayName ASC"; 
SetBinder.DataSource = SetTable; 
foreach (DataColumn column in SetTable.Columns) 
     { 
      if (!Controls.ContainsKey("in" + column.ColumnName)) continue; 
      //This code's mostly here so I don't have to have a list of controls 
      //with bindings for each when it's mostly the same for all of them. 
      Controls["in" + column.ColumnName].DataBindings.Add("Text", SetBinder, column.ColumnName); 
     } 
this.DataBindings.Add("SetID", SetBinder, "SetID"); //doesn't work 

回答

0

我的工作了:屬性必須是公開的,你需要的BindableAttribute添加到屬性,像這樣:

[Bindable(true)] 
public Guid SetID { get; set; }