DataGridView and Xml as DataSource

  • Thread starter Thread starter black_sun
  • Start date Start date
B

black_sun

Hi to all,
I have a problem with a DataGridView.
I have this xml file:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<art>
<F1>Intestazione</F1>
<F2>Monitor</F2>
</art>
<art>
<F1>Intestazione</F1>
<F2>Periodo</F2>
<F3>01/01/2008 - 31/07/2008</F3>
</art>
<art>
<F1>Intestazione</F1>
<F8>Totale</F8>
<F9>Anno2003</F9>
<F10>Anno2004</F10>
<F11>Anno2005</F11>
<F12>Anno 2006</F12>
<F13>Anno 2007</F13>
</art>
</NewDataSet>

Then there is the code to insert the xml file into DataGrivView:
Dim tempDataSet As New DataSet
tempDataSet.ReadXml("C:\prova.xml")
DataGridView1.DataSource = tempDataSet.Tables(0).DefaultView

The problem is that in the DataGridView the sort of the columns is not
F1, F2, F3, F8, F9.... but F1, F8, F9, F10... F2, F3...

How can I get the sort F1, F2, F3, F8, F9?

Thank you and Merry Xmas!!!

Bye
BlackSun
 
Hi to all,
I have a problem with a DataGridView.
I have this xml file:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <art>
    <F1>Intestazione</F1>
    <F2>Monitor</F2>
  </art>
  <art>
    <F1>Intestazione</F1>
    <F2>Periodo</F2>
    <F3>01/01/2008 - 31/07/2008</F3>
  </art>
  <art>
    <F1>Intestazione</F1>
    <F8>Totale</F8>
    <F9>Anno2003</F9>
    <F10>Anno2004</F10>
    <F11>Anno2005</F11>
    <F12>Anno 2006</F12>
    <F13>Anno 2007</F13>
  </art>
</NewDataSet>

Then there is the code to insert the xml file into DataGrivView:
Dim tempDataSet As New DataSet
tempDataSet.ReadXml("C:\prova.xml")
DataGridView1.DataSource = tempDataSet.Tables(0).DefaultView

The problem is that in the DataGridView the sort of the columns is not
F1, F2, F3, F8, F9.... but F1, F8, F9, F10... F2, F3...

How can I get the sort F1, F2, F3, F8, F9?

Thank you and Merry Xmas!!!

Bye
BlackSun

Hi,
Though you can struggle with ICompare and other sorting techniques for
the columns, only based on your code, you can sort the "view" in
DataGridView by removing item form index 1 for 6 times, because there
are 6 columns grater than F3. Then refill DataGridView with remaining
columns.

Shortly, call RetrieveData() sub which should work to sort the desired
view in DataGridView:
(Actually sorting is never done, just manipulated view of DataGridView
to make as if columns were sorted.)

Sub RetrieveData()
Dim tempDataSet As New DataSet
tempDataSet.ReadXml("C:\prova.xml")
DataGridView1.DataSource = tempDataSet.Tables(0).DefaultView

For x As Integer = 1 To 6
DataGridView1.Columns.RemoveAt(1)
Next

' Remember to call that sub
reFillDgView()
End Sub

Sub reFillDgView()
Dim tempDataSet As New DataSet
tempDataSet.ReadXml("C:\prova.xml")
DataGridView1.DataSource = tempDataSet.Tables(0).DefaultView
End Sub

Hope this helps,

Onur Güzel
(e-mail address removed)
(e-mail address removed)
 
Back
Top