Welcome to WindowsClient.net | Sign in | Join

Small Business Developer

Sponsors





  • advertise here

Tags

No tags have been created or used yet.

XML and Strongly-Typed Datasets - Part 2

I did a bit of research and found another way to allow design-time usage of an XML file.  This one has a few more steps than my previous post, but I think it is more useful.  I am going to provide a simple example in this post, but will follow it up with a more complex example.  You will need the Visual Basic Power Pack XML to Schema tool installed, which you can download from here - http://msdn.microsoft.com/en-us/vbasic/bb840042.aspx.  Hopefully this walkthrough will be helpful.

  1. Create a new windows project in VB 2008.
  2. Add a new xml file, call it books.xml.  When you see the xml designer you can replace the code with the books.xml code from here - http://msdn.microsoft.com/en-us/library/ms762271.aspx 
  3. Set the Copy To Output Directory to "Copy Always" for this example.
  4. Now add another new file and select the XML to Schema template.image
  5. I called the file BooksSchema.xsd and then click add.  Another screen will pop up, click on Add from File.image
  6. Select the books.xml file you created and click ok.image 
  7. Click Ok again.
  8. Now, you can click on the Data Sources Tab and it will show the catalog dataset.  Drag the Books icon onto the form design surface and it will automatically create a datagridview with the columns from the XML file.image
  9. Now go the code behind and add this line of code to the Load event.
  10. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)  _ Handles Me.Load

    Catalog.ReadXml("Books.xml")

    End Sub

  11. In the end it should look like this:image
  12. Now, if you want to view the schema like you do a dataset, you need to right click on the schema and select Open with... and select Dataset Editor from the list.  Click OK.  A warning will come up, but click yes.  Now you will see the XML schema like you do a regular dataset. image

Next week, I will use an example where there are relationships in the XML and use that to create multiple datagridviews with a parent-child relationship.

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter