Configuring WinCC ListBox Content from Dynamic Data

David Krause6 min read
SiemensTechnical ReferenceWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

WinCC can change a List object at runtime when the target runtime exposes writable list properties. The demonstrated WinCC 7.0 method sets the line count, selects each line by index, and writes its text through C-script. WinCC flexible is a separate engineering and runtime environment, so first confirm that its script object model exposes equivalent writable properties; a WinCC 7.0 C function is not a VBScript interface for WinCC flexible.

Symptom interpretation

The requested behavior is a dependent list: selecting a parent value, such as a brand, changes the child choices, such as models. The term dynamic list here means that runtime logic replaces the available entries after a selection or data-change event. It does not merely hide static entries or change which preconfigured text list is displayed.

Observed behavior Engineering meaning Diagnostic check
The child list never changes The update event is not running, or the displayed control is still bound to static engineering data. Trigger the script manually and watch the line count and selected index.
The correct number of lines appears, but text is blank The script resized the object but did not write each selected line. Confirm the sequence SelIndex followed by SelText for every entry.
Only one line changes repeatedly The selected index is not advanced before each text write. Log or display the index used for every write.
A supplied project will not open The engineering versions or service-pack levels differ. Compare the project version with the installed WinCC flexible version before diagnosing the script.

Runtime property mechanism

The WinCC 7.0 example addresses an object named List and writes three properties. NumberLines defines the number of visible list entries. SelIndex selects the entry to be edited, and SelText replaces the text at that selected entry. The example uses indices 1, 2, and 3, then restores the selection to 1.

#include "apdefap.h"
void OnRButtonDown(char* lpszPictureName, char* lpszObjectName,
                   char* lpszPropertyName, UINT nFlags, int x, int y)
{
    SetPropWord(lpszPictureName,"List","NumberLines",3);
    SetPropWord(lpszPictureName,"List","SelIndex",1);
    SetPropChar(lpszPictureName,"List","SelText","Custom line 1");
    SetPropWord(lpszPictureName,"List","SelIndex",2);
    SetPropChar(lpszPictureName,"List","SelText","Custom line 2");
    SetPropWord(lpszPictureName,"List","SelIndex",3);
    SetPropChar(lpszPictureName,"List","SelText","Custom line 3");
    SetPropWord(lpszPictureName,"List","SelIndex",1);
}

Order matters. Resize the list before addressing its entries, select a valid line before assigning text, and leave the control on a deliberate final selection. The right-button event in the example is a test trigger. A dependent production list should invoke the update after the parent selection changes or after a new dataset has been accepted.

Platform and version boundary

WinCC 7.0 C-script and WinCC flexible VBScript use different runtime object models. Function names such as SetPropWord and SetPropChar establish a working method for the WinCC 7.0 List object only. Copying them into a WinCC flexible VB script will not create equivalent functionality.

  1. Identify the actual engineering product and runtime hosting the screen. Distinguish WinCC 7.0 from WinCC flexible.
  2. Open the scripting editor or object browser and inspect the Symbolic IO Field or list control. Look for writable members corresponding to line count, item index, and item text.
  3. If those members exist, use the same resize-select-write sequence with the documented VBScript member names.
  4. If the runtime exposes only a process value and an engineering TextList association, treat that TextList as configuration data. Build the changing choices with runtime-writable display fields, a fixed set of indexed slots, or another control whose item collection is writable.
  5. Align the engineering installation before exchanging projects. The reported exchange involved WinCC flexible 2007, 2008, and SP1 references, but it did not define a universal conversion path between them.

This inspection is the decision point. A database connection cannot compensate for a control whose runtime interface does not permit item insertion or text replacement.

Dynamic population procedure

Separate data retrieval from control population. The query layer returns a bounded collection of rows; the display layer validates that collection and then rewrites the list. This prevents a partial query, null value, or changing row count from leaving old selections mixed with new ones.

  1. Read the selected parent key, such as the chosen brand. Use a stable identifier rather than display text when the data source provides one.
  2. Request the matching child rows from the configured data source. Define an explicit sort order so the operator sees a repeatable sequence.
  3. Copy the returned display values and their associated identifiers into a temporary runtime buffer. Reject unusable rows before changing the displayed list.
  4. Record the returned row count. Clear or resize the old list before writing new entries; otherwise entries from the previous parent selection can remain visible.
  5. For the WinCC 7.0 List method, write the count to NumberLines. For every valid row, write its target SelIndex and then its SelText.
  6. Store the identifier associated with each displayed row outside the text itself. On operator selection, translate the selected index back to that identifier.
  7. Set a deliberate final selection. Select the first valid row only if automatic selection is acceptable; otherwise retain an explicit no-selection state when the runtime supports it.
  8. Publish the new list only after every row has been prepared. If retrieval fails, preserve the last accepted list or present a defined unavailable state instead of displaying a half-written result.

Verification checks

  1. Check 1: event execution. Change the parent selection once. Expect exactly one completed child-list refresh for that accepted change.
  2. Check 2: row count. Compare the query result count with the displayed line count. Expect NumberLines, or its platform equivalent, to equal the number of accepted rows.
  3. Check 3: index-to-text mapping. Inspect the first, a middle, and the last entry. Expect each displayed text value to match the buffered value assigned to that index.
  4. Check 4: selection mapping. Select each inspected row and read the resulting identifier. Expect the identifier to belong to the same source record as the displayed text.
  5. Check 5: shrinking dataset. Change from a parent with more children to one with fewer. Expect no stale text below the new final row.
  6. Check 6: empty result. Select a parent with no accepted rows. Expect a defined empty or unavailable state, with no identifier left over from the previous selection.
  7. Check 7: query failure. Interrupt or invalidate the data request using the installation's approved test method. Expect no partially rewritten list and no false valid selection.

Recurring implementation pitfalls

Wrong practice Result Correction
Treating a static TextList as a database result set Runtime values change, but the engineering text entries remain fixed. Use a runtime-writable item interface or an indexed display architecture.
Writing text before setting the line count The target index can be outside the current list. Resize first, then select and write each line.
Using display text as the database key Duplicate or translated labels can select the wrong record. Maintain a separate index-to-identifier mapping.
Updating the visible control while rows are still arriving The operator can see or select an incomplete dataset. Stage rows in memory and publish one accepted set.
Ignoring project-version differences A project-opening failure is mistaken for a script defect. Match WinCC flexible versions and service-pack levels before functional testing.
Leaving the previous selection active after repopulation The selected index can refer to a different record in the new dataset. Reset the selection and mapped identifier after each refresh.

FAQ

Can I use the WinCC 7.0 C-script directly in WinCC flexible?

No. SetPropWord, SetPropChar, NumberLines, SelIndex, and SelText describe the demonstrated WinCC 7.0 List method. Inspect the WinCC flexible VBScript object model for writable equivalents before implementing the sequence.

Can I fill a WinCC list from a changing database column?

Yes when the runtime provides both data access and a writable list-item interface. Read the matching rows into a temporary buffer, resize the list, write each indexed label, and retain a separate mapping from list index to source identifier.

Does writing SelText automatically add another list line?

The demonstrated sequence sets NumberLines first, selects a valid SelIndex, and then writes SelText. Follow that order instead of relying on a text assignment to increase the list size.

Does the dynamic list pass final verification when the text changes?

Text alone is insufficient. Change the parent value, select the first, middle, and last child entries, and expect every displayed label, selected index, and stored source identifier to reference the same record.

Back to blog