access drop-down list items using vb.net

B

bleitner

I've filled a drop-down list box with a data connection and I want to access
those items in the list using vb.net managed code so I can assign the last
item in the list to a variable, any suggestion on how I can achieve this?

Thanks!
Bob
 
F

Franck Dauché

Hi Bob,

You need to access your secondary data source (used to fill your drop-down).

Here is C# code to access it (you will need to adapt to VB):

IXMLDOMDocument3 oSecondDoc =
(IXMLDOMDocument3)thisXDocument.DataObjects["tblTest"].DOM;
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"");
IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");

to get to fldTest in that doc:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
IXMLDOMNode oField1 = oN.selectSingleNode("@fldTest");
}
}

Hope that it gets you started....

Regards,

Franck Dauché
 
B

bleitner

Hi Frank,

Thank you for the reply, unfortunately I little experience with C# and am
having a hard time converting. For instance, in the first line it looks like
you're declaring a variable, oSecondDoc to type IXMLDocument3 to a data
source "tblTest", but what's the "3" for? Then in the second section it
looks like you're iterating through each of the child nodes of the returned
data connection testing for the list box items that match the field
"@fldTest", which is the field I would be looking for. Does that sound
correct?

Thanks!
Bob

Franck Dauché said:
Hi Bob,

You need to access your secondary data source (used to fill your drop-down).

Here is C# code to access it (you will need to adapt to VB):

IXMLDOMDocument3 oSecondDoc =
(IXMLDOMDocument3)thisXDocument.DataObjects["tblTest"].DOM;
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"");
IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");

to get to fldTest in that doc:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
IXMLDOMNode oField1 = oN.selectSingleNode("@fldTest");
}
}

Hope that it gets you started....

Regards,

Franck Dauché


bleitner said:
I've filled a drop-down list box with a data connection and I want to access
those items in the list using vb.net managed code so I can assign the last
item in the list to a variable, any suggestion on how I can achieve this?

Thanks!
Bob
 
F

Franck Dauché

Hi Bob,

You need to use a IXMLDOMDocument3 and not a IXMLDOMDocument because the
setProperty is available through a Document3 only.

I am not a VB person, but the VB.Net version would be something like:

Dim oSecondDoc As IXMLDOMDocument3 =
CType(thisXDocument.DataObjects("tblTest").DOM, IXMLDOMDocument3)
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields'")
Dim oSecDocNode As IXMLDOMNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields")

Dim oNode As IXMLDOMNode
Dim oField1 As IXMLDOMNode
For Each oNode In oSecDocNode.childNodes
If (oNode.nodeType = DOMNodeType.NODE_ELEMENT) Then
oField1 = oNode.selectSingleNode("@fldTest")
End If
Next

Hope that it helps.

Regards,

Franck Dauché


bleitner said:
Hi Frank,

Thank you for the reply, unfortunately I little experience with C# and am
having a hard time converting. For instance, in the first line it looks like
you're declaring a variable, oSecondDoc to type IXMLDocument3 to a data
source "tblTest", but what's the "3" for? Then in the second section it
looks like you're iterating through each of the child nodes of the returned
data connection testing for the list box items that match the field
"@fldTest", which is the field I would be looking for. Does that sound
correct?

Thanks!
Bob

Franck Dauché said:
Hi Bob,

You need to access your secondary data source (used to fill your drop-down).

Here is C# code to access it (you will need to adapt to VB):

IXMLDOMDocument3 oSecondDoc =
(IXMLDOMDocument3)thisXDocument.DataObjects["tblTest"].DOM;
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"");
IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");

to get to fldTest in that doc:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
IXMLDOMNode oField1 = oN.selectSingleNode("@fldTest");
}
}

Hope that it gets you started....

Regards,

Franck Dauché


bleitner said:
I've filled a drop-down list box with a data connection and I want to access
those items in the list using vb.net managed code so I can assign the last
item in the list to a variable, any suggestion on how I can achieve this?

Thanks!
Bob
 
B

bleitner

you rock Frank! it works great, thank you!

Bob

Franck Dauché said:
Hi Bob,

You need to use a IXMLDOMDocument3 and not a IXMLDOMDocument because the
setProperty is available through a Document3 only.

I am not a VB person, but the VB.Net version would be something like:

Dim oSecondDoc As IXMLDOMDocument3 =
CType(thisXDocument.DataObjects("tblTest").DOM, IXMLDOMDocument3)
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields'")
Dim oSecDocNode As IXMLDOMNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields")

Dim oNode As IXMLDOMNode
Dim oField1 As IXMLDOMNode
For Each oNode In oSecDocNode.childNodes
If (oNode.nodeType = DOMNodeType.NODE_ELEMENT) Then
oField1 = oNode.selectSingleNode("@fldTest")
End If
Next

Hope that it helps.

Regards,

Franck Dauché


bleitner said:
Hi Frank,

Thank you for the reply, unfortunately I little experience with C# and am
having a hard time converting. For instance, in the first line it looks like
you're declaring a variable, oSecondDoc to type IXMLDocument3 to a data
source "tblTest", but what's the "3" for? Then in the second section it
looks like you're iterating through each of the child nodes of the returned
data connection testing for the list box items that match the field
"@fldTest", which is the field I would be looking for. Does that sound
correct?

Thanks!
Bob

Franck Dauché said:
Hi Bob,

You need to access your secondary data source (used to fill your drop-down).

Here is C# code to access it (you will need to adapt to VB):

IXMLDOMDocument3 oSecondDoc =
(IXMLDOMDocument3)thisXDocument.DataObjects["tblTest"].DOM;
oSecondDoc.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"");
IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");

to get to fldTest in that doc:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
IXMLDOMNode oField1 = oN.selectSingleNode("@fldTest");
}
}

Hope that it gets you started....

Regards,

Franck Dauché


:

I've filled a drop-down list box with a data connection and I want to access
those items in the list using vb.net managed code so I can assign the last
item in the list to a variable, any suggestion on how I can achieve this?

Thanks!
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top