Binding data to an object created in .Net 2.0

I am making a binding in .Net 2.0. It was a hassle! I have a DataTable (I tried to use a DataRow but it didn't have anything) and a BindingNavigator (which seemed to be the magic ingredient) with a BindingSource, and I programmatically bind controls to it. However, one of my columns is an ID, which I certainly don't want to show to the user, but I still need to be able to access it. Since I am using the ID to make some more calls to the database, I would like to have these calls as well when they change.

My thought was to create my own property as code of the appropriate type and then bind to it. It doesn't work, although binding to textbox properties using the same code does. Why not?

Here is the code in my UserControl so you can see what I am doing:

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 mostly here so I don't have to have a list of controls
            //with bindings for each when it 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

      

+1


source to share


1 answer


I worked this out: the property must be public and you need to add a BindableAttribute to the property, like so:



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

      

0


source







All Articles