Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to display related tables in a datagridview where data comes from xml file

Posted on 2008-09-29
6
Medium Priority
?
603 Views
Last Modified: 2013-11-15
Hi fellow experts

I have a database with a main table called Cards which has a related table called Editions.One field in Cards (Edition) is related to the primary key in Editions. The database was originally an access database, and I have converted it into an xml file

I have the code below to populate a datagridview with the data from the cards table. This works Ok, but I just get the edition field being displayed with the codes used in the editions table. How can I get the table to display the full name of the edition which is a field in the editions table.

I'm very familliar with vb.net 2008 but my database manipulation skills are a bit rusty at the moment, so any help will be appreciated


Dim fn As String = "Cards.xml"
        CardsDataSet = New System.Data.DataSet
        CardsDataSet.ReadXmlSchema(fn)
        CardsDataSet.ReadXml(fn)
        Me.DataGridView1.DataSource = CardsDataSet
        DataGridView1.DataMember = "Cards"

Open in new window

0
Comment
Question by:ChloesDad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22605004
That is not a problem with a straight-forward solution.  The DataGridView doesn't really support binding to multiple tables, so you need to get all the data together into one table, or use the DataGridView in unbound, virtual mode.
0
 
LVL 15

Author Comment

by:ChloesDad
ID: 22609268
Hi TheLearnedOne,

So wgat are my options, Can I create a class with all of the fields as public properties and use that to lookup the actual value from the second table. Each record could then be an element of an arraylist or a hashtable. Can I then link the collection to the datagridview?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22609316
Using a generics BindingList(Of T) would be better choice:

Dim productList As New BindingList(Of Product)

When you bind that to the DataGridView, modify the list, and refresh the DataGridView, it will reflect the changes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Author Comment

by:ChloesDad
ID: 22609329
Thanks for your prompt reply, I'll give it a go
0
 
LVL 15

Author Comment

by:ChloesDad
ID: 22609981
Thanks, that has worked a treat. I now have all my data in the datagrid.

I also have a treeview that I use to create a filter.

I have the following

        Me.DataGridView1.DataSource = CardsList

How can I apply a filter to the data without creating the cardlist again?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22610934
Ok, now you are asking for something more complicated :)

Look here for a possible solution:

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic53718.aspx


Class FilterBindingList(Of T) 
    Inherits BindingList(Of T) 
    Private allItems As New List(Of T)() 
    Private predicate As Predicate(Of T) 
    
    Public Sub Filter(Predicate__1 As Predicate(Of T)) 
        predicate = Predicate__1 
        Filter() 
    End Sub 
    
    Private Sub Filter() 
        MyBase.Items.Clear() 
        For Each obj As T In allItems 
            If (predicate Is Nothing) OrElse predicate(obj) Then 
                MyBase.Items.Add(obj) 
            End If 
        Next 
        OnListChanged(New ListChangedEventArgs(ListChangedType.Reset, -1)) 
    End Sub 
    
    Protected Overloads Overrides Sub InsertItem(index As Integer, item As T) 
        allItems.Add(item) 
        MyBase.InsertItem(index, item) 
    End Sub 
    Protected Overloads Overrides Sub RemoveItem(index As Integer) 
        allItems.Remove(Items(index)) 
        MyBase.RemoveItem(index) 
    End Sub 
    Protected Overloads Overrides Sub ClearItems() 
        allItems.Clear() 
        MyBase.ClearItems() 
    End Sub 
    Protected Overloads Overrides Sub SetItem(index As Integer, item As T) 
        allItems(allItems.IndexOf(Items(index))) = item 
        MyBase.SetItem(index, item) 
    End Sub 
End Class 

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question