Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / August 2007

Tip: Looking for answers? Try searching our database.

how to set listbox value dynamically?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
daska - 21 Aug 2007 23:20 GMT
Hi

I am working on an InfoPath browser based form. I have created a multiselect
list box that contains two nodes, one for a checkbox and the other for a text
box. I succeeded in adding new rows programmatically but now I dont know how
to set the values of the inner nodes. For example, I copied following code
from the MS site:
XPathNavigator DOM = this.MainDataSource.CreateNavigator();
XPathNodeIterator nodes = DOM.Select("/my:myFields/my:Options/my:Option");
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterator nodesText =
nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

                       while (nodesText.MoveNext())
                       {
                           Console.Write(nodesText.Current.Name);
                           Console.WriteLine(nodesText.Current.Value);
                         }

This code shows how to read from the inner nodes but How can we set the
values of these inner nodes?

Thanks,

Daska
S.Y.M. Wong-A-Ton - 22 Aug 2007 07:22 GMT
You can use

nodesText.Current.SetValue("YourValue");

Double-check the node type before you do, because you may get an error if
the node is not of type "Text". So do something like

if (nodesText.Current.NodeType == XPathNodeType.Text)
{
 nodesText.Current.SetValue("YourValue");
}

---
S.Y.M. Wong-A-Ton

> Hi
>
[quoted text clipped - 22 lines]
>
> Daska
daska - 22 Aug 2007 14:24 GMT
Thank you so much. I am almost there. I have two descendants. One is checkbox
and the second is a text box. The current code populates the checkboxes. How
to populate the text boxes? Kindly look at the code below:

XPathNodeIterator nodesText =
nodesNavigator.SelectDescendants(XPathNodeType.Text, false);  --> This only
selects the checkbox!!! (How to select the textbox here???)

                       while (nodesText.MoveNext())
                       {
                           //Console.Write(nodesText.Current.Name);
                           //Console.WriteLine(nodesText.Current.Value);
                           if (nodesText.Current.NodeType ==
XPathNodeType.Text)
                           {
                               nodesText.Current.SetValue("true"); --> This
sets the checkboxes value!!!!
                           }

                       }

I appreciate your help!! Thanks once again.

Daska

p.s. I love your articles! There are very few InfoPath experts out there!
You are one of them!

> You can use
>
[quoted text clipped - 37 lines]
> >
> > Daska
S.Y.M. Wong-A-Ton - 23 Aug 2007 01:44 GMT
I'm not sure in what context the code you copied was being used, so not sure
why the Text nodes were retrieved, but try this instead:

XPathNodeIterator nodesText =
nodesNavigator.SelectDescendants(XPathNodeType.Element, false);
while (nodesText.MoveNext())
{
   if (nodesText.Current.Name == "my:field1")
       nodesText.Current.SetValue("true");

   if (nodesText.Current.Name == "my:field2")
       nodesText.Current.SetValue("MyValue");
}

or you could change the entire lot to this:

XPathNavigator DOM = this.MainDataSource.CreateNavigator();
XPathNodeIterator nodes = DOM.Select("/my:myFields/my:Options/my:Option",
NamespaceManager);
while (nodes.MoveNext())
{
   nodes.Current.SelectSingleNode("my:field1",
NamespaceManager).SetValue("true");
   nodes.Current.SelectSingleNode("my:field2",
NamespaceManager).SetValue("MyValue");
}

where my:field1 is your checkbox and my:field2 your text box.

I'm glad you enjoy the articles I publish. Thank you for your positive
feedback.
---
S.Y.M. Wong-A-Ton

> Thank you so much. I am almost there. I have two descendants. One is checkbox
> and the second is a text box. The current code populates the checkboxes. How
[quoted text clipped - 65 lines]
> > >
> > > Daska
daska - 23 Aug 2007 22:08 GMT
I can't thank you enough. You proved to be a Messiah. Thank you very very much.

Regards

Daska

> I'm not sure in what context the code you copied was being used, so not sure
> why the Text nodes were retrieved, but try this instead:
[quoted text clipped - 99 lines]
> > > >
> > > > Daska
S.Y.M. Wong-A-Ton - 24 Aug 2007 03:06 GMT
You're welcome!
---
S.Y.M. Wong-A-Ton

> I can't thank you enough. You proved to be a Messiah. Thank you very very much.
>
[quoted text clipped - 105 lines]
> > > > >
> > > > > Daska
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.