Solved

Export DataGrid to XML

Posted on 2006-11-29
12
666 Views
Last Modified: 2008-02-01
I am looking for a way to export a datagrid to xml regardless of its source type.  I have several datagrids where their source types are of type DataTable and ArrayList.  I was attempting to write a class where the datagrid would be passed and the class would handle the export.  Any suggestions?
0
Comment
Question by:Cwinde01
[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
  • 6
  • 5
12 Comments
 
LVL 7

Expert Comment

by:Dimandja
ID: 18040150
Try http://tinyurl.com/ufc87

In VB.NET, the code would be:

         Dim sw as new StringWriter()
         Dim hw as new  HtmlTextWriter(sw)
         DataGrid1.RenderControl(hw)

         With hw
            .Indentation = 4
            .WriteEndDocumnet()
         End with

         hw.Close()
         MsgBox(sw.ToString())


 
0
 

Author Comment

by:Cwinde01
ID: 18040211
I am using Vb.Net 2003.  I don't think RenderControl is a member of the datagrid in 2003.  Any other suggestions?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18044841
There was an assumption made--that you were using the DataGrid web control with an ASP.NET application.  If you are using the WinForms DataGrid, then how are you binding the DataGrid?  DataTable?  DataSet?

Bob
0
Independent Software Vendors: 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!

 

Author Comment

by:Cwinde01
ID: 18045569
There are several grids that are loaded.  Most of the time we will set datagrid.datasource = dataset.tables("TableName") and other times we will set datagrid.datasource = ArrayList.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18045598
Saving a DataSet to XML can be as easy as using DataSet.WriteXml, but the ArrayList is a different story all together.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18045712
That is what I was afraid of.  I have used the DataSet.WriteXml before but I was trying to find a way to extract the data from the datagrid.datasource.  Maybe another solution might be to set the datagrid.datasource to a dataset somehow.  But I have not been able to do that either.  I tried CType(Me.DataGrid.DataSource, DataTable), but when the arraylist is the datasource CType is unable to convert it into a DataTable.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18046788
I need to find out the reason for mixing DataSet/DataTable and ArrayList as a binding source.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047183
Sorry for the confusion.  I have an application that has several datagrids.  

* Some of the datagrids are loaded using a DataSet.  

* Then there are other datagrids that are loaded using a dataview because I need to filter the dataset based on the selection made from another datagrid.  

* Then I have one instance where I have a datagrid that has two different datasources.  I query the first datasource and load the results into a arraylist then I query the second source and load the results in the same arraylist.  Then assign the arraylist to the datagrid.datasource so that it appears as one source.  I realize now that the data should have been loaded manualy using a datatable.  I was hoping that I would not have to rewrite the piece that loads the arraylist.

I have one scenario where I want to show all the different grids on one xml page and show a summary for each grid.  I would have a style sheet to handle the summary but  I need to get the different grids into the same doc.

Hope that helps.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18047758
Hmmm, maybe you could something like this:

  Dim dv1 As New DataView(ds.Tables("Table1"))
  Dim dv2 As New DataView(ds.Tables("Table2"))

  dv1.RowFilter = "filter goes here"
  dv2.RowFilter = "filter goes here"

  Me.DataGrid1.DataSource = dv1
  Me.DataGrid2.DataSource = dv2

Then, you could create an XML file from the DataView.  You would only need to create one method to create the file.

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047865
It appears that I will need to convert everthing to a dataview or a datatable, is that correct?

I guess there is no way to extrapolate the datagrid.datasource to some other type of datasource? (arraylist, datatable, dataview)
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 18047955
1) You don't need an ArrayList

2) The DataView constructor takes a DataTable as an argument

3) With the DataView you can apply different filters for each separate instance

4) If you bind all DataGrid controls to a DataView, then you can retrieve the DataSource this way:

  Dim dv As DataView = CType(CType(source, DataGrid).Datasource, DataView)

Bob
0
 

Author Comment

by:Cwinde01
ID: 18047975
It looks like that should work.

Thank you for your help and explanations.  Your patience has been greatly appreciated.
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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