2.0 BindingSource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The question I have is how to connect an instance variable to a binding
source. In the IDE, I can create a new Data Source pointing to an object in
my class. It creates the source based on the definition of the class, not a
specific instance of that class on, say, a form. I can drag that Data Source
definition onto the form and create a DataGrid and an associated
BindingSource object. Great. Sweet. But how do I link that DataGrid to the
instance of that object in the form, so that data in the instance of the
object is displayed in the grid, and changes in the grid are serialized to
the object? I see there is a DataSource property in the BindingSource, but
in the visual editor, that is set to the DataSource in the solution...
 
Hi William
I see there is a DataSource property in the BindingSource,
but in the visual editor, that is set to the DataSource in the
solution...

In the visual editor die DataSource property of the BindingSource
object is set to the type of the object which should be displayed (in
the designer, you select a Type within your project). If you look at
the designer generated code there is something like (let´s take a
class named "Person" as DataSource):

myBindingSource.DataSource = typeof(Person);

--> so the designer is able to display (generate) the right columns for
you and you see them in the designer (in your grid).

When you want to display some data in the grid (eg when a button is
pressed) you do the following:

.... buttonXYZ_pressed(...) {

// load data
ICollection<Person> persons = LoadPersons(.....);

// bind it to the BindingSource
myBindingSource.DataSource = persons.
}



Did I understand your problem right?

hth,
Chris
 
Yes, you do. It was unclear to me that I should use the same property. The
way it comes from the designer led me to believe that the DataSource, being
assigned a type object, was used to map the schema (so to speak) of the
object... Thanks.
 
Back
Top