使用表达式生成数据集中的自定义列 [英] Generation custom column in dataset with expression
问题描述
在我的示例XML中,对象是ZB。那个ZB有两个点,AAD和AAG。两个点都有共同点,分为|字符。这是一种固定格式,我必须处理它。
因为在我们的软件中,我们使用数据集中的数据。因此,我们使用以下命令将XML转换为数据集:
Dim myDS As DataSet
Dim fsReadXml As 新 System.IO.FileStream(myXMLFile,System.IO.FileMode.Open)
myDS.ReadXml(fsReadXml)
之后,我的数据集中有4个表:
-ZB
-AAE
-AAG
-point
自动添加关系和隐藏ID。之后,我使用此代码连接2个datagrids。一个包含所有对象和第二个网格的数据网格向我显示数据网格1中所选对象的协调:
Dim myBS 作为 新 BindingSource
myBS.DataSource = myDS
DataGridView1.DataSource = myBS
DataGridView1.DataMember = ZB
DataGridView2.DataSource = myBS
DataGridView2.DataMember = ZB.ZB_AAE.AAE_point
到目前为止一切顺利,一切正常!
我单击ZB对象后,可以将标签或其他文本框数据绑定到该点。它的代码如下:
TextBox1.DataBindings.Clear()
TextBox1.DataBindings.Add( New 绑定( text,myBS, ZB.ZB_AAG.AAG_point.pos))
我想要什么?
我想在一个数据网格中使用对象和协作。所以我想创建一个视图,添加一个自定义列,并在一个数据网格中查看XML中的所有字段(AAA,AAD,AAF,AAG)。
我尝试了以下方法。我试过的所有注释行。我无法找到构建表达式的正确方法,因此显示了coördinates:
Dim 测试 As DataColumn = myDS.Tables( ZB)。Columns.Add( test, GetType ( String ))
Test.Expression = ZB.ZB_AAE.AAE_point
' Test.Expression =子(ZB.ZB_AAE).point
' Test.Expression =Child(ZB_AAE) ).point
' Test.Expression =Child(point)
' Test.Expression =Child(p os)
' Test.Expression =ZB_AAE.point
' Test.Expression =ZB.ZB_AAE.point.pos
< span class =code-comment>' Test.Expression =point
' Test.Expression =point.pos
' Test.Expression =Parent.ZB_AAE.AAE_point.pos
' Test.Expression =父级(ZB_AAE).AAE_point
Test.Expression =Parent.ZB
' Test.Expression =ZB_AAE.AAE_point.pos
' Test.Expression =Child.ZB_AAE.poin t.pos
您可以使用此XML进行测试:
<? xml 版本 = 1.0 encoding = ISO-8859-1 standalone = 是 ? > ;
<! - 文件标题 - >
< DATA xmlns:nl = http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation = file:EN13508 .xsd xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance xmlns:gml = http://www.opengis.net / gml >
< ZB >
< < span class =code-leadattribute> AAA > AAA < / AAA >
< < span class =code-leadattribute> AAD > 1 < / AAD >
< < span class =code-leadattribute> AAE >
< gml:point srsName = Netherlands-RD srsDimension = 2 >
< gml:pos > 123 | 456 < / gml:pos >
< / gml:point >
< / AAE >
< AAF > 2 < / AAF >
< AAG >
< GML:POI nt srsName = Netherlands-RD srsDimension = 2 >
< span class =code-keyword>< gml:pos > 234 | 567 < / gml:pos >
< / gml:point > ;
< / AAG >
< / ZB >
< ZB >
< AAA > AAA < / AAA >
< AAD > 3 < / AAD >
< AAE >
< gml:point srsName = Netherlan ds-RD srsDimension = 2 >
< ; gml:pos > 345 | 678 < / gml:pos >
< / gml:point >
< span class =code-keyword>< / AAE >
< AAF > 4 < span class =code-keyword>< / AAF >
< AAG >
< gml:point srsName = Netherlands-RD srsDimension = 2 >
< gml:pos > 456 | 789 < / gml:pos >
< / gml:point >
< / AAG >
< / ZB >
< < span class =code-leadattribute> / DATA >
In my sample XML the object is "ZB". That "ZB" has two points, "AAD" and "AAG". Both points have coördinates, devided by the "|" character. This is a fixed format, I have to deal with it.
Because in our software, we use the data in a dataset. So we convert the XML tot a dataset with the command:
Dim myDS As DataSet
Dim fsReadXml As New System.IO.FileStream(myXMLFile, System.IO.FileMode.Open)
myDS.ReadXml(fsReadXml)
After that, I have 4 tables in my dataset:
-ZB
-AAE
-AAG
-point
Automaticly there are relations and hidden id's added. After that, I connect 2 datagrids with this code. One datagrid with all objects and the second grid shows me the coördinates of the selected object in datagrid 1:
Dim myBS As New BindingSource
myBS.DataSource = myDS
DataGridView1.DataSource = myBS
DataGridView1.DataMember = "ZB"
DataGridView2.DataSource = myBS
DataGridView2.DataMember = "ZB.ZB_AAE.AAE_point"
So far so good, everything works fine!
I can databind labels or other textboxes to the point, after clicking a "ZB" object. Its with this code:
TextBox1.DataBindings.Clear()
TextBox1.DataBindings.Add(New Binding("text", myBS, "ZB.ZB_AAG.AAG_point.pos"))
What do I want?
I want the objects and coördinates in one datagrid. So I want to create a view, adding a custom column, and see all fields from XML back in one datagrid ("AAA", "AAD", "AAF", "AAG").
I tried the following. All commented lines I tried. I can't find the proper way to build a expression so the coördinates were shown:
Dim Test As DataColumn = myDS.Tables("ZB").Columns.Add("test", GetType(String))
Test.Expression = "ZB.ZB_AAE.AAE_point"
'Test.Expression = "Child(ZB.ZB_AAE).point"
'Test.Expression = "Child(ZB_AAE).point"
'Test.Expression = "Child(point)"
'Test.Expression = "Child(pos)"
'Test.Expression = "ZB_AAE.point"
'Test.Expression = "ZB.ZB_AAE.point.pos"
'Test.Expression = "point"
'Test.Expression = "point.pos"
'Test.Expression = "Parent.ZB_AAE.AAE_point.pos"
'Test.Expression = "Parent(ZB_AAE).AAE_point"
'Test.Expression = "Parent.ZB"
'Test.Expression = "ZB_AAE.AAE_point.pos"
'Test.Expression = "Child.ZB_AAE.point.pos"
You can use this XML to test:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!-- File Header -->
<DATA xmlns:nl= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:EN13508.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml">
<ZB>
<AAA>AAA</AAA>
<AAD>1</AAD>
<AAE>
<gml:point srsName="Netherlands-RD" srsDimension="2">
<gml:pos>123|456</gml:pos>
</gml:point>
</AAE>
<AAF>2</AAF>
<AAG>
<gml:point srsName="Netherlands-RD" srsDimension="2">
<gml:pos>234|567</gml:pos>
</gml:point>
</AAG>
</ZB>
<ZB>
<AAA>AAA</AAA>
<AAD>3</AAD>
<AAE>
<gml:point srsName="Netherlands-RD" srsDimension="2">
<gml:pos>345|678</gml:pos>
</gml:point>
</AAE>
<AAF>4</AAF>
<AAG>
<gml:point srsName="Netherlands-RD" srsDimension="2">
<gml:pos>456|789</gml:pos>
</gml:point>
</AAG>
</ZB>
</DATA>
这篇关于使用表达式生成数据集中的自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!