Dynamic Sections

T

_t

I would like to be able to add some sections to a form based on the results
from a drop-down list. To accomplish this, I have applied conditional
formatting to the sections to show and hide them based on the drop-down list
value.

The problem seems to be that each of the sections still get added to the xml
even if they were hidden on the form. This makes the xml very messy and hard
to use.

Does anyone know of a way I can get these sections to appear when the right
value is chosen from the drop-down list, but not appear in the xml if they
are hidden?

Thanks.

_t
 
S

Scott L. Heim [MSFT]

Hi,

If you want to dynamically add sections based on a drop-down list selection
then you will need to look at using: XDocument.View.ExecuteAction. One of
the actions for this method is an "insert" so in the OnAfterChange event of
your drop-down list you could check the value and execute the appropriate
action.

Here is some sample code to insert a section when the selection in my
drop-down list is the letter "A":

Dim objMyDropdown
Set objMyDropdown =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtMyDropdown")

If objMyDropdown.text = "A" Then
XDocument.View.ExecuteAction "xCollection::insert", "group2_1"
Else
XDocument.UI.Alert "Some message here"
End If

** NOTE: To determine the correct "section identification (i.e. group2_1 as
above), right-click on your Repeating Section, choose Properties and select
the Advanced tab.

In addition, so that a section does not show up by default when the form is
opened, you can do this:

- Open your XSN in Design View
- From the Tools menu choose Default Values
- Uncheck the top level group for your section

Lastly, you will probably want to complete these steps as well:

- Right-click on your Repeating Section and choose Properties
- On the Data tab click the Modify button
- Click Edit Default Values
- From the "Apply the options on this dialog box" section, choose "Only
when the user inserts this section"

Hopefully this will get you where you need to be!

Best regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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