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
Solved

How to load grid based on values in xml file?

Posted on 2010-11-23
11
323 Views
Last Modified: 2012-05-10
Hello,

I'm trying to load several grids based on the values in my xml file. For example my xml file is in the following format:
 
<?xml version="1.0" standalone="yes" ?> 
- <Root>
  <NSN_ID>1</NSN_ID> 
  <NSN>1305-00-028-1111</NSN> 
  <Type>1</Type> 
  </Row>
- <Row>
- <Root>
  <NSN_ID>2</NSN_ID> 
  <NSN>1305-00-028-1112</NSN> 
  <Type>1</Type> 
  </Row>
- <Row>

- <Root>
  <NSN_ID>3</NSN_ID> 
  <NSN>1305-00-028-1113</NSN> 
  <Type>1</Type> 
  </Row>
- <Row>
  <NSN_ID>4</NSN_ID> 
  <NSN>1305-00-028-1114</NSN> 
  <Type>2</Type> 
  </Row>
- <Row>
- <Row>
  <NSN_ID>5</NSN_ID> 
  <NSN>1305-00-028-1115</NSN> 
  <Type>2</Type> 
  </Row>
- <Row>
  <NSN_ID>3</NSN_ID> 
  <NSN>1305-00-028-1116</NSN> 
  <Type>3</Type> 
  </Row>
- <Row>
  <NSN_ID>4</NSN_ID> 
  <NSN>1305-00-028-1117</NSN> 
  <Type>4</Type> 
  </Row>
  </Root>

I would like to load Grid1 with NSN values where Type = 1, Grid2 with NSN values where type = 2, Grid3 with NSN values where Type = 3 etc..

Open in new window

How do I accomplish this when in the load event of my windows form?

Thank you.

Victor
0
Comment
Question by:vcharles
  • 5
  • 4
11 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 34201433
What you can do is read the whole XML, get the structure according the nodes and create a dataset with it, then create the grids and assign to each one the differents filters of your dataset and on this way you will have one dataset with your xml and all the grids that you want by the filter that you select.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34204050
Here is how to read xml into a dataset

http://www.a1vbcode.com/snippet-2391.asp

Once you have the dataset, you can do this

Dim dTemp1, dTemp2, dTemp3 as New DataTable

With dataset1.Tables(0)
    .DefaultView.RowFilter = "Type=1"
    dTemp1 = .DefaultView.ToTable()
    .DefaultView.RowFilter = "Type=2"
    dTemp2 = .DefaultView.ToTable()
    .DefaultView.RowFilter = "Type=3"
    dTemp3 = .DefaultView.ToTable()
End With

grid1.DataSource = dTemp1
grid2.DataSource = dTemp2
grid3.DataSource = dTemp3
0
 

Author Comment

by:vcharles
ID: 34205475
Hello,

I'm trying the code below, but getting error message "Can not find column "Type" ", any idea what I'm doing wrong?

 Dim xmlPath1 As String
' ReaderOptions xml files
xmlPath1 = System.IO.Path.Combine(Application.StartupPath, "NSN.xml")  'grid1
'Populate dataset
dtsetcol1.ReadXml(xmlPath1)
 Dim dTemp1, dTemp2, dTemp3 As New DataTable

        With dtsetcol1.Tables(0)
            .DefaultView.RowFilter = "Type=1"
            dTemp1 = .DefaultView.ToTable()
            .DefaultView.RowFilter = "Type=2"
            dTemp2 = .DefaultView.ToTable()
            .DefaultView.RowFilter = "Type=3"
            dTemp3 = .DefaultView.ToTable()
            End With

        Grid1.DataSource = dTemp1
        Grid2.DataSource = dTemp2
        Grid3.DataSource = dTemp3

Thanks,

Victor
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34205517
After reading the xml, check the Tables count. Set it as a datasource to a grid and see if the data is loaded correctly.
0
 

Author Comment

by:vcharles
ID: 34208414
How do you check the Tables count? below is my xml file, could the format also be the problem?

<?xml version="1.0" standalone="yes"?>
<Root>
  <Row>
    <NSN_ID>0</NSN_ID>
    <NSN>NA</NSN>
    <Type>0</Type>
  </Row>
  <Row>
    <NSN_ID>1</NSN_ID>
    <NSN>1305-00-028-1111</NSN>
    <Type>1</Type>
  </Row>
  <Row>
    <NSN_ID>2</NSN_ID>
    <NSN>1305-00-028-1112</NSN>
    <Type>2</Type>
  </Row>
  <Row>
    <NSN_ID>3</NSN_ID>
    <NSN>1305-00-028-1113</NSN>
    <Type>3</Type>
  </Row>
  <Row>
    <NSN_ID>4</NSN_ID>
    <NSN>1305-00-028-1114</NSN>
    <Type>4</Type>
  </Row>

<Row>
    <NSN_ID>3</NSN_ID>
    <NSN>1305-00-028-1115</NSN>
    <Type>5</Type>
  </Row>
  <Row>
    <NSN_ID>4</NSN_ID>
    <NSN>1305-00-028-1116</NSN>
    <Type>6</Type>
  </Row>
</Root>
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34208428
Did you try to set it as a data source to grid?
0
 

Author Comment

by:vcharles
ID: 34208663
I'm using the following code for the grid, what should I be using?

Grid1.DataSource = dTemp1
Grid2.DataSource = dTemp2
Grid3.DataSource = dTemp3

Thanks,

Victor
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 167 total points
ID: 34209179
No. After

dtsetcol1.ReadXml(xmlPath1)

Do this

Grid1.DataSource = dtSetCol1
Grid1.DataBind()

Then confirm the data is populating correctly. Also check the column names etc.
0
 

Author Comment

by:vcharles
ID: 34282663
Please close this case.

Thank You.

Victor
0
 

Author Closing Comment

by:vcharles
ID: 34309806
Thank You.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.net and XML report from SCCM 5 41
VB.net Open Folder in Windows Explorer 3 50
VB.net and sql server 4 45
Access Schema 6 23
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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