"过滤器"从XML数据文件到datagrid的数据 [英] "Filter" data from XML datafile into datagrid

查看:60
本文介绍了"过滤器"从XML数据文件到datagrid的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我使用xml文档中的数据填充数据网格,它工作正常

但....

现在我将数据过滤到网格,所以只有数据显示来自

我设定的标准。


我的代码现在非常简单填充网格


Dim strProj As String


Dim MyA As String()

Dim dsCodes As New DataSet

Dim fsReadXml As New System.IO.FileStream(XMLFile,

System.IO.FileMode.Open)


Dim XmlReader作为新的XmlTextReader(fsReadXml)


dsCodes.ReadXml(XmlReader)

XmlReader.Close()

''填充网格

DataGrid1.DataSource = dsCodes.Tables(XMLTable)

我不会在我的网格中显示我的客户的所有customerdata只有

Proj No = strProj


我的XML文件如下所示:


<?xml version =''1.0''编码=''utf-8''?>

<! - 代码输入形成 - >

< xml>

< projectinfo>

< Cust No =''2298''Name =' 'Company1''Adress1 =''Adress1''Adress2

=''方框999''

Adress3 =''161 02 BROMMA''Phone =''08- 999 91 90''传真=''''

Trakt =''0''/>

< Proj No =''445640''Name =' '正在进行''/>

< / projectinfo>

< projectinfo>

< Cust No ='''2324'' Name =''Company2''Adress1 =''xxxxx''Adress2 =''Box

230''

Adress3 =''127 24 HOLMEN''Phone =' '08 -999 99 00''Faxs =''''

Trakt =''0''/>

< Proj No ='''232401''姓名'''正在进行''/>

< Proj否=''232402''姓名=''测试''/>

< Proj否=''232403''Name =''Startup''/>


< / projectinfo>

& lt; / xml>

我已经搜索了这个,但我找不到任何关于它的信息,也许

某人已经找到了解决方案或提示,我可以找到它。 br />

//关心Thomas

Hi,

I fill a datgrid with data from a xml document, it works fine
But....
Now I will to filter the data to the grid so only the data shows from
the criteria that I set.

My code now is very simple to fill the grid

Dim strProj As String

Dim MyA As String()
Dim dsCodes As New DataSet
Dim fsReadXml As New System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader As New XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()
''fill the grid
DataGrid1.DataSource = dsCodes.Tables(XMLTable)
I wont to show all customerdata for my customer in my grid there only
Proj No = strProj

My XML file looks like this:

<?xml version=''1.0'' encoding=''utf-8'' ?>
<!--Code Information-->
<xml>
<projectinfo>
<Cust No=''2298'' Name=''Company1'' Adress1=''Adress1'' Adress2
=''Box 999''
Adress3=''161 02 BROMMA'' Phone=''08-999 91 90'' Fax=''''
Trakt=''0'' />
<Proj No=''445640'' Name=''Ongoing'' />
</projectinfo>
<projectinfo>
<Cust No=''2324'' Name=''Company2'' Adress1=''xxxxx'' Adress2=''Box
230''
Adress3=''127 24 HOLMEN'' Phone=''08-999 99 00'' Fax=''''
Trakt=''0'' />
<Proj No=''232401'' Name=''Ongoing'' />
<Proj No=''232402'' Name=''Test'' />
<Proj No=''232403'' Name=''Startup'' />

</projectinfo>
</xml>
I have search for this but I couldnt find anything about it, maybe
someone has got an solution or a tips there I could find it.

//Regards Thomas

推荐答案

你必须使用DataView,因为只有DataView才有能力

过滤数据或对其进行排序。所以,你需要做这样的事情:


dvCodes =新的DataView(dsCodes.Tables(代码))

dvCodes。 Sort =" Name" ''*只有你想要它排序

dvCodes.RowFilter =" Proj No =''" &安培; strProj& "''"

DataGrid1.DataSource = dvCodes


只需将DataView分配给datagrid而不是DataSet。

Thomas A写道:
You have to use a DataView because only a DataView has the capability to
filter data or sort it. So, you''ll need to do something like this:

dvCodes = New DataView(dsCodes.Tables("Codes"))
dvCodes.Sort = "Name" '' * only if you wanted it sorted
dvCodes.RowFilter = "Proj No = ''" & strProj & "''"
DataGrid1.DataSource = dvCodes

and just assign the DataView to the datagrid instead of the DataSet.
Thomas A wrote:


我用一个xml文档中的数据填充数据网格,它工作正常
但是......
现在我将数据过滤到网格,所以只有数据显示我设置的标准。

现在我的代码填充网格非常简单


Dim strProj As String

Dim MyA As String()
Dim dsCodes作为新数据集
Dim fsReadXml作为新的System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader作为新的XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()

''填充网格
DataGrid1.DataSource = dsCodes.Tables(XMLTable)

我不会为我的客户显示所有customerdata在我的网格中只有
Proj No = strProj

我的XML文件如下所示:

<?xml version =''1.0''coding =' 'utf-8''?>
<! - 代码信息 - >
< xml>
< projectinfo>
< Cust No =' '2298''姓名='''公司1''Adress1 =''Adress1''Adress2
=''方框999''
Adress3 =''161 02 BROMMA''Phone =''08-999 91 90''Fax =''''
Trakt =''0''/>
< Proj No ='''445640''Name =''正在进行''/>
< / projectinfo>
< projectinfo>
< Cust No =''2324''Name =''Company2''Adress1 ='''xxxxx''Adress2 =''Box
230''
Adress3 =''127 24 HOLMEN''Phone ='''08-999 99 00''Faxs =''''
Trakt =''0''/>
< Proj No =''232401''Name =''正在进行''/>
< Proj No ='''232402''Name =''Test' />
< Proj No =''232403''Name =''Startup''/>

< / projectinfo>
< / xml>

我已经搜索了这个,但我找不到任何关于它的信息,也许
某人已经找到了解决方案或提示我可以找到它。

//问候Thomas
Hi,

I fill a datgrid with data from a xml document, it works fine
But....
Now I will to filter the data to the grid so only the data shows from
the criteria that I set.

My code now is very simple to fill the grid

Dim strProj As String

Dim MyA As String()
Dim dsCodes As New DataSet
Dim fsReadXml As New System.IO.FileStream(XMLFile,
System.IO.FileMode.Open)

Dim XmlReader As New XmlTextReader(fsReadXml)

dsCodes.ReadXml(XmlReader)

XmlReader.Close()
''fill the grid
DataGrid1.DataSource = dsCodes.Tables(XMLTable)
I wont to show all customerdata for my customer in my grid there only
Proj No = strProj

My XML file looks like this:

<?xml version=''1.0'' encoding=''utf-8'' ?>
<!--Code Information-->
<xml>
<projectinfo>
<Cust No=''2298'' Name=''Company1'' Adress1=''Adress1'' Adress2
=''Box 999''
Adress3=''161 02 BROMMA'' Phone=''08-999 91 90'' Fax=''''
Trakt=''0'' />
<Proj No=''445640'' Name=''Ongoing'' />
</projectinfo>
<projectinfo>
<Cust No=''2324'' Name=''Company2'' Adress1=''xxxxx'' Adress2=''Box
230''
Adress3=''127 24 HOLMEN'' Phone=''08-999 99 00'' Fax=''''
Trakt=''0'' />
<Proj No=''232401'' Name=''Ongoing'' />
<Proj No=''232402'' Name=''Test'' />
<Proj No=''232403'' Name=''Startup'' />

</projectinfo>
</xml>
I have search for this but I couldnt find anything about it, maybe
someone has got an solution or a tips there I could find it.

//Regards Thomas



你好Copyco,

问题是使用的XML文件不是数据集而是XML文件

(格式正确)。

(它有3个表但我无法找到一种与

数据集方式建立关系的方法)。

就我现在所看到的而言,最好从它做出一个很好的数据表,但是如果我们看到一个更好的答案,我等待
等等。 />

当我看到代码而不是我认为托马斯不是一个真正的expirienced与

数据集,数据表等等因此我不知道什么是最好的

回答。


(如果他开始制作数据集XML文件,可能会更好e而不是XML

文件)

Cor
Hi Copyco,

The problem is that the used XML file is not a dataset but a XML file
(wellformed).
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
As far as I see it now, is making a nice datatable from it the best, but I
am waiting if we see a better answer also.

When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer.

(Maybe it is better if he starts to make a dataset XML file instead of a XML
file)
Cor


Cor,
当我看到的代码比我认为托马斯不是一个真正的expirienced与
数据集,数据表等,因此我不知道什么是最好的答案。
嗯?


我希望您意识到使用DataColumn.ColumnMapping&

DataRelation.Nested属性DataSet可以创建托马斯的XML

显示了!


如果Thomas有任何东西以非常先进的方式使用DataSet,在

中有些情况是首选。

(它有3个表,但我找不到用
数据集方式与它建立关系的方法)。


请记住,当DataSet读取XML时,它会自动定义(推断)

关系。


尝试以下代码在Thomas的代码中看到上面的设置在

动作中。


For Each table As DataTable in ds.Tables

Debug.WriteLine(table.TableName," table")

Debug.Indent()

For Each Column As DataColumn in table.Columns

Debug.WriteLine(column.ColumnName," column")

Debug.Indent()

Debug.WriteLine(column.ColumnMapping," mapping" ;)

Debug.Unindent()

下一页

Debug.Unindent()

下一页

For Each relation As DataRelation in ds.Relations

Debug.WriteLine(relation.RelationName," relation")

Debug.Indent()

Debug.WriteLine(relation.Nested," nested")

Debug.WriteLine(relation.ParentTable," parent")

Debu g.Indent()

For Each Column As DataColumn in relation.ParentColumns

Debug.WriteLine(column.ColumnName," column")

下一页

Debug.Unindent()

Debug.WriteLine(relation.ChildTable," child")

Debug.Indent()

For Each Column As DataColumn in relation.ChildColumns

Debug.WriteLine(column.ColumnName," column")

Next

Debug.Unindent()

Debug.Unindent()

下一页

希望这有帮助

周杰伦


" Cor" < no*@non.com>在留言中写道

新闻:eS ************** @ TK2MSFTNGP09.phx.gbl ...你好Copyco,

问题是使用过的XML文件不是数据集而是XML文件
(格式良好)。
(它有3个表但我找不到在
数据集中与它建立关系的方法方式)。
就我现在所看到的而言,最好是从中做出一个很好的数据表,但我等待,如果我们也能看到更好的答案。

我看到代码比我认为托马斯不是一个真正的expirienced与
数据集,数据表等,因此我不知道什么是最好的答案。

(也许如果他开始创建数据集XML文件而不是
XML文件会更好。

Cor
When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer. Huh?

I hope you realize that using the DataColumn.ColumnMapping &
DataRelation.Nested properties a DataSet can create the XML that Thomas
showed!

If any thing Thomas is using the DataSet in a very advanced method, which in
some cases is preferred.
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
Remember when the DataSet reads the XML it will automatically define (infer)
the relationship.

Try the following code after Thomas''s code to see the above settings in
action.

For Each table As DataTable In ds.Tables
Debug.WriteLine(table.TableName, "table")
Debug.Indent()
For Each column As DataColumn In table.Columns
Debug.WriteLine(column.ColumnName, "column")
Debug.Indent()
Debug.WriteLine(column.ColumnMapping, "mapping")
Debug.Unindent()
Next
Debug.Unindent()
Next
For Each relation As DataRelation In ds.Relations
Debug.WriteLine(relation.RelationName, "relation")
Debug.Indent()
Debug.WriteLine(relation.Nested, "nested")
Debug.WriteLine(relation.ParentTable, "parent")
Debug.Indent()
For Each column As DataColumn In relation.ParentColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.WriteLine(relation.ChildTable, "child")
Debug.Indent()
For Each column As DataColumn In relation.ChildColumns
Debug.WriteLine(column.ColumnName, "column")
Next
Debug.Unindent()
Debug.Unindent()
Next
Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:eS**************@TK2MSFTNGP09.phx.gbl... Hi Copyco,

The problem is that the used XML file is not a dataset but a XML file
(wellformed).
(It has 3 tables but I cannot find a way to make a relation with it in a
dataset way).
As far as I see it now, is making a nice datatable from it the best, but I
am waiting if we see a better answer also.

When I see the code than I asume Thomas is not a real expirienced one with
dataset, datatables etc. and therefore I do not know what is the best
answer.

(Maybe it is better if he starts to make a dataset XML file instead of a XML file)
Cor


这篇关于&QUOT;过滤器&QUOT;从XML数据文件到datagrid的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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