XML和Datagrid问题 [英] XML and Datagrid problem

查看:74
本文介绍了XML和Datagrid问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经制作了一个程序,可以打开,查看,编辑并保存到xml

但是我有问题

我注意到我的XML文档中有一些字段具有与相同的父节点相同的子节点.

这是Iam谈论的内容的一个示例

Hey

I have made a program that opens,views ,edits and saves to a xml

But I have a problem

I notice that I have some fields in my XML document that have child nodes as the same Parent nodes.

Heres a sample of what Iam talking about

<root>
<ai_ratio>
 <ai_ratio>0.35</ai_ratio>
 <discipline_id>27</discipline_id>
 <id>1</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
 <ai_ratio>
 <ai_ratio>0.05</ai_ratio>
 <discipline_id>28</discipline_id>
 <id>2</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
 <ai_ratio>
 <ai_ratio>0.35</ai_ratio>
 <discipline_id>29</discipline_id>
 <id>3</id>
 <season_id>1</season_id>
 <star_level>0</star_level>
 </ai_ratio>
</root>







由于存在这些子节点,因此数据视图无法正确显示.它不会像应有的那样将子点头 ai_ratio 应用于数据网格视图中的列,并且会生成一个空行,因为在认为它有很多新数据.

这是我用于渲染datagrid的代码,它可能不是最好的方法:(但它可以正常工作









because of these child nodes the data view does not come up right.It doesn''t apply the child nod ai_ratio to a column in the data grid view like it should and it generates a empty row because in thinks its a new lot of data .

Here is my code Iam using to render the datagrid .Its probably not the best method :( but it is working



Public Class Form1
 Dim ds As New DataSet("Dataset1")

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim table As String
 table = ListBox1.Text

 Dim filePath As String
 OpenFileDialog1.ShowDialog()

 filePath = OpenFileDialog1.FileName
 ds.ReadXml(filePath)
 

 With (DataGridView1)
  .DataSource = ds
  ''define what table is used 
  .DataMember = table


 End With
 End Sub


 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
 
 Try
  DataGridView1.DataMember = ListBox1.Text
 Catch ex As Exception

 End Try
 End Sub

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 SaveFileDialog1.ShowDialog()

 Dim savepath1 As String
 savepath1 = SaveFileDialog1.FileName
 ds.WriteXml(savepath1)
 End Sub
End Class



这是应用程序的图片
< < img src ="http://img12.imageshack.us/img12/4452/82669986.jpg"border =" 0"alt =""/> 已上传 ImageShack.us
通过ImageShack.us>
上传
那么我该怎么做才能从数据集中过滤这些子节点.新方法还是有我可以包含的代码来处理这些子节点.

Cheers



Heres a pic of the app
<<img src="http://img12.imageshack.us/img12/4452/82669986.jpg" border="0" alt="" /> Uploaded with ImageShack.us
Uploaded with ImageShack.us>

So what do I have to do to filter these childnodes from the dataset .New method or is there so code which I can include to deal with these child nodes .

Cheers

推荐答案

没有直接的方法可以实现,您可以逐个读取每个子节点并创建数据表并将其绑定到网格.
There is no direct way to achieve it, you can read every child node one by one and create datatable and bind it to grid.


这篇关于XML和Datagrid问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆