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 / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Show master column in details datagridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jordi Rico - 07 Mar 2008 12:43 GMT
Hi,
I've been searching quite a lot and can't find any answer.
Let's put an example:

I have 2 tables:

Master:
 idMaster int
 masterName nvarchar(50)

Details:
 idDetails int
 idMaster int
 detailsName nvarchar(50)
 quantity int

I have a datagridview and I want to display data from Details table,
but I also want to display a column with masterName from it's parent
table. This column won't be editable, but I must be able to change
some columns from details (for example quantity) and update database
with this changes. I remark that masterName will be only informative.
I have been searching and can't do this thing. I thought it would be
easier but I'm stuck with this. Any help will be appreciated.

Thanks in advance,

Jordi Rico
Steve Gerrard - 07 Mar 2008 16:07 GMT
> Hi,
> I've been searching quite a lot and can't find any answer.
[quoted text clipped - 19 lines]
> I have been searching and can't do this thing. I thought it would be
> easier but I'm stuck with this. Any help will be appreciated.

Step 1: put both tables in the same dataset, if they are not already.

Step 2: define a Relation in that dataset, linking the two tables by idMaster.

Step 3: add a column to the Details table, with an expression displaying a field
from the parent table.

Step 4: add a column to your grid to display that field.

So if you start with

Dim Master As DataTable
Dim Details As DataTable

you can then do

Dim MyDataSet As New DataSet

MyDataSet.Tables.Add Master
MyDataSet.Tables.Add Detail

MyDataSet.Relations.Add( _
   New DataRelation("MasterToDetail", _
   Master.Columns("idMaster"), _
   Details.Columns("idMaster")))

Details.Columns.Add( _
   New DataColumn("MasterName", _
   GetType(String), _
   "Parent(MasterToDetail).masterName"))

Voila. You can now display the MasterName column of the Details table.
Jordi Rico - 08 Mar 2008 19:41 GMT
Thanks,
I'll give a try when I go back to the office.

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.