all groups > dotnet windows forms databinding > august 2006 >
You're in the

dotnet windows forms databinding

group:

Databinding 3 datagridviews to a 3 tier hirerarchial object


Databinding 3 datagridviews to a 3 tier hirerarchial object Ollie
8/21/2006 5:59:02 AM
dotnet windows forms databinding:
Hello.

I have been doing quite a bit of research to try and find out the best way
for me to bind my object to 3 datagrid views (and other items on my form).
My object is as follows, 1 project has many sections, each section has many
items, and each item has many lines.

The first datagrid displays the Sections for a project. The user clicks a
section, which then loads up the items for that project on the second grid,
the user clicks an item which then loads up the lines for that item on the
thrid grid.

I have created my project object using the IEditableObject.

Is there any way to load up all this information without using the selection
change events of the datagridviews? Half the reason I used the
IEditableObject was because I thought I could automate almost the whole
program.

I hope this post is understandable.


To give you a full description of my object, to access an items line i'd use
the code -

project.sections.section(1).items.item(1).lines.line(1)


Thanks in advance for the help






Re: Databinding 3 datagridviews to a 3 tier hirerarchial object Grady Morgan
8/22/2006 1:41:46 PM
What you are trying to do is called "Master-Detail" binding (according
to Brian Noyes). Use heirarchial BindingSources (which are
CurrencyManagers) to encapsulate your data:

<code>
ProjectBindingSource.DataSource = m_aProjects;

SectionBindingSource.DataSource = ProjectBindingSource;
SectionBindingSource.DataMember = "Sections"; //property which gets
Project's sections

ItemBindingSource.DataSource = SectionBindingSource;
ItemBindingSource.DataMember = "Items";
</code>

Then, bind each dataGrid to it's respective BindingSource.

This can also be done with a DataSet and DataRelations.

I am not sure about the implications of having null selections or no
current item in the binding sources, but this should at least be a
start.

-Grady


[quoted text, click to view]
Re: Databinding 3 datagridviews to a 3 tier hirerarchial object Ollie
8/23/2006 6:31:01 AM
Thank you so so so much.

You dont understand how happy it made me to see me write 8 lines of code to
sync 4 datagridviews. It is working perfectly.

I had read up on the hierarchial discussions, but none of them explained it
as clearly as you did.

More than a start.

Thanks again and again.


[quoted text, click to view]
AddThis Social Bookmark Button