Vb.net 保留数据集行顺序XmlWriter vb

Vb.net 保留数据集行顺序XmlWriter vb,vb.net,datatable,dataset,xmlwriter,Vb.net,Datatable,Dataset,Xmlwriter,尝试编写一些代码来通过用户界面更改XML文件中的元素顺序。问题是:如何控制通过WriteXML写入的物理存储顺序元素 例如,我想转换: <Image Name="Middle" file="Sauce.png" /> <Image Name="Top" file="Cheese.png" /> <Image Name="Bottom" file="PizzaBase.png" /> 终于明白了。您必须将更新后的表从数据集中写入临时表,然后清除数据集中的表,然

尝试编写一些代码来通过用户界面更改XML文件中的元素顺序。问题是:如何控制通过
WriteXML写入的物理存储顺序元素

例如,我想转换:

<Image Name="Middle" file="Sauce.png" />
<Image Name="Top" file="Cheese.png" />
<Image Name="Bottom" file="PizzaBase.png" />

终于明白了。您必须将更新后的表从数据集中写入临时表,然后清除数据集中的表,然后将临时表的行逐个写入数据集中的匹配表。代码(直接从完整脚本中删除道歉,但应说明过程):


然后像往常一样使用XMLWriter。多亏了Puropoix。

您能展示一下您是如何进行重新订购的吗?它是在DGV、视图、DT中还是在哪里?
<Image Name="Top" file="Cheese.png" />
<Image Name="Middle" file="Sauce.png" />
<Image Name="Bottom" file="PizzaBase.png" />
<Image Name="Middle" file="Sauce.png" />
<Image Name="Bottom" file="PizzaBase.png" />
<Image Name="Top" file="Cheese.png" />
 Private Sub _RigRowUp_Click(sender As Object, e As EventArgs) Handles _RigRowUp.Click
        If IsNothing(_RigImgsDGV.DataSource)
            Return
        End If
        Dim selectedRow As DataRow = _RigXMLImgsDS.Tables("Image").Rows(_RigImgsDGV.CurrentRow.Index)
        Dim selectedindex As Integer = _RigXMLImgsDS.Tables("Image").Rows.IndexOf(selectedRow)
        If selectedindex <= 0 Then
            Return
        End If
        Dim newRow As DataRow = _RigXMLImgsDS.Tables("Image").NewRow()
        newRow.ItemArray = selectedRow.ItemArray
        _RigXMLImgsDS.Tables("Image").Rows.Remove(selectedRow)
        _RigXMLImgsDS.Tables("Image").Rows.InsertAt(newRow, selectedindex - 1)
        _RigImgsDGV.ClearSelection()
        _RigImgsDGV.CurrentCell = _RigImgsDGV.Rows(selectedindex - 1).Cells(0)
        _RigImgsDGV.Rows(selectedindex - 1).Selected = True
    End Sub
  _RigImgsDGV.DataSource = New BindingSource(_RigXMLImgsDS.Tables("Image"), Nothing)
Dim _tempDT As DataTable
    _tempDT = _RigXMLImgsDS.Tables("Image").Copy()
    _RigXMLImgsDS.Tables("Image").Clear()
    For Each DataRow In _tempDT.Rows
        _RigXMLImgsDS.Tables("Image").ImportRow(DataRow)
    Next