Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

Related tables for grids in vs 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Magnus Blomberg - 12 Jan 2006 20:47 GMT
Hello!

I'm quite new to VS 2005, and tries to connect several controls at my form.
I thought this should be simple without writing code, but I can't get it to
work.

I have one dataset with two related tables.
In my form I have two datagridviews. The first has datasource set to the
dataset and datamember set to the first table.
The second has the datasource set to the dataset and datamember set to the
second table.
I've tried more combinations, but really don't understand what to do and how
it works.

What I want: I click a row in the first datagridview, for instance with a
primary key value set to 17.
When I do this I only want to see those rows with foreign key value set to
17 in my second datagrid (and in the second table).
I also want to be able to add rows to the second datagridview, so that the
foreign key value is automatically set to 17.

Shouldn't this be basic functionality, that not requires code???

Please help
/Magnus
Bart Mermuys - 12 Jan 2006 23:17 GMT
Hi,

> Hello!
>
[quoted text clipped - 12 lines]
> how
> it works.

In NET2.0 it's more convenient if you put BindingSource's between them, so
it should look like:

MasterBindingSource
   DataSource=someDataSet
   DataMember="MasterTable"

ChildBindingSource
   DataSource=someDataSet
   DataMember="MasterTable.RelationToChildTable"

MasterDataGridView
  DataSoure = MasterBindingSource

ChildDataGridView
  DataSource = ChildBindingSource

> What I want: I click a row in the first datagridview, for instance with a
> primary key value set to 17.
[quoted text clipped - 4 lines]
>
> Shouldn't this be basic functionality, that not requires code???

Make sure you have a Data Source ( Typed DataSet + TableAdapters ).

Menu->Data->Show Data Sources, create a new Data Source for the two tables
if you haven't already.  Then right click on the DataSet and choose open
'Edit DataSet with designer" and verify there is a relation between the two
DataTable (indicated by a line), if there isn't then right-click on the
empty space and choose add-relation.

Now inside Data Sources window you should see your two tables.  The tables
have grids to the left of them while the fields have TextBox's on the left.
So you can either drag the master table to the Form or some of the master
table fields.
Then you should also see inside Data Sources window that the master table
has a field which also has a grid to the left (child table because of the
relation).  Now you can also drag that child table on the Form or any of
it's field.

That should setup most things, except you still need to add some code to the
save button.

See also:
http://www.msdn.microsoft.com/vbasic/default.aspx?pull=/library/en-us/dnvs05/htm
l/newdtastvs05.asp


HTH,
Greetings

> Please help
> /Magnus
Bart Mermuys - 12 Jan 2006 23:32 GMT
[Snipped]

> In NET2.0 it's more convenient if you put BindingSource's between them, so
> it should look like:
[quoted text clipped - 6 lines]
>    DataSource=someDataSet
>    DataMember="MasterTable.RelationToChildTable"

Made a mistake with ChildBindingSource, should be:
ChildBindingSource
   DataSource=MasterBindingSource
   DataMember="RelationToChildTable"

> MasterDataGridView
>   DataSoure = MasterBindingSource
>
> ChildDataGridView
>   DataSource = ChildBindingSource

Greetings

>> What I want: I click a row in the first datagridview, for instance with a
>> primary key value set to 17.
[quoted text clipped - 35 lines]
>> Please help
>> /Magnus
Cor Ligthert [MVP] - 13 Jan 2006 08:17 GMT
Magnus,

> Shouldn't this be basic functionality, that not requires code???

Net is not the same as Office MS Access.

It gives you a lot rapid design tools to do the most standard things.

However as soon as we seen things as updating than we are allowed (have to
do) it ourselves.

I hope this helps,

Cor

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.