|
I have a dataset which contains one simple Courts table. I have created a strongly typed dataset using the VS 2005 wizard. I have also created a Court object which I'd like to bind to the dataset such that the Court object is loaded with the current record's data. I think I need to implement or inherit something in my Court object, but I have several choices and am having a hard time finding examples and information on the differences. Most everything along these lines is talking about UI controls which already have this functionality.
Currently I have a propertygrid which displays the single Court object that the user can edit. I would like to bind the Court object to the dataset.
Originally I had a bunch of text boxes bound to the dataset, and a combo box was used to select the current record. I decided I prefer the look of the propertygrid much more, and it doesn't require several lines of code for each property.
I also decided that there are going to be cases where I'm going to want to be able to load the data from the dataset into simple court objects instead of into a UI.
I believe I'm going to have to implement an interface or inherit from another object to make the Court object bindable. I'm just not sure which one is the way to go. I tried inheriting from Microsoft.VisualStudio.Tools.Applications.Runtime.BindableComponent and then the following:
court.DataBindings.Add("CodeText",codesCourtBindingSource,"CodeText");
This works fine, but only does a single property of course. Something I've done in the past is like this: court.DataBindings.Add("",codesCourtBindingSource,"");
Normally this would fill in matching properties across the objects being bound, which saves me from writing a line of code for every property in the object. This didn't work in this case though, and I have no idea why.
Additionally, now my property grid displays the DataBindings property of the object. I need to be able to apply the [BrowsableAttribute(false)] attribute to the property. I guess maybe I'm going to have to override(or maybe hide?) the inherited properties, add the attribute, and then just pass through the operations on nthe property.
Also it will get more complicated when I am working with multiple rows and need to manage which one is current. I think I will get away with having a single court object, and manage traversing through the records via the bindingsource object that sits between my court object and dataset.
Any ideas or suggestions? Primarily I need help deciding what my Court object should inherit from or what interface I should implement that will get me two way data binding without a tremendous amount of code.
|