cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate dropdownbykey dynamically ?

Amey-Mogare
Contributor
0 Kudos

Hi,

I have a list of 5 names to be put into 3 dropdownbykey boxes..

Now what I want is once a name gets seletced in one of the three dropdown, it should not appear in other two dropdowns.

For example, 5 names are :- Amey, Mike, John, Bryan, Sam.

Then if 'Mike' is selected in one of the dropdowns, it should not appear in rest two dropdowns..

If anybody has done this kinda thing of came across it, then pls let me know as soon as possible !

Accepted Solutions (1)

Accepted Solutions (1)

former_member197348
Active Contributor
0 Kudos

Hi,

For this you need use 3 different nodes. Populate initially all these with all 5 values.

Create 3 actions and bind them to the property of onActionSelect() of the dropDownBoxes.

In dropdown1 action

do like this:

//code sample

//delete the dropdown1 selected value from dropdown2

IPrivate<View>.I<node2>Element el;

for (int i = 0; i < wdContext.<node2>().size(); i++)

{

el=wdContext.<node2>().get<node2>()ElementAt(i);

// compare with value selected in dropDown1

if(el.get<attributename>().equalsIgnoreCase(wdContext.<node1>().current<node1>()Element()))

{

wdContext.<node2>().removeElement(el);

}

}

//end of code sample

repeat this //code sample for node3.

//END OF ACTION1

In dropdown2 action

repeat this //code sample for node1.

repeat this //code sample for node3.

In dropdown3 action

repeat this //code sample for node1.

repeat this //code sample for node2.

regards,

Siva

Answers (3)

Answers (3)

Former Member
0 Kudos

Why do you need to use DropDownByKey? You might also use 3 DropDownByIndex UI elements bound to 3 context nodes with 3 supply functions.

Add to each drop-down list an action. In the action handler, call invalidate() for each of the other context nodes. Example:


void onAction<Node1>Selected()
{
  wdContext.node<Node2>().invalidate();
  wdContext.node<Node3>().invalidate();
}

The supply function for e.g. the second node will look like this:


void supply<Node2>(I<Node2> node, ...)
{
  I<Node1>Element selection1 = wdContext.current<Node1>Element();
  I<Node3>Element selection3 = wdContext.current<Node3>Element();
  for (int i = 0; i < NAMES.length; ++i)
  {
    if ( selection1 != null && NAMES<i>.equals(selection1.getName()) ) continue;
    if ( selection3 != null && NAMES<i>.equals(selection3.getName()) ) continue;
    I<Node2>Element e = node.createAndAdd<Node2>Element();
    e.setName(NAMES<i>); 
  }
}

//@@begin others
static final String[] NAMES = { "Amey", "Mike", "John", "Bryan", "Sam" };
//@@end

Armin

Amey-Mogare
Contributor
0 Kudos

Thanks alot Armin,

That was very helpful piece of advice..

I'll try this and let u kno of i need some more help..

Thanks once again,

Regards,

Amey

Amey-Mogare
Contributor
0 Kudos

Hey Armin,

But tell me one thing, I want to retain the value which i selected in 1st dropdown.

If we call invalidate for other nodes, then wont i lose value which i selected in 1st dropdown?

That is, when i move on to 2nd dropdown, the selection which i made in 1st dropdown should not change. Will above method ensure this?

Do u get what i mean?

Pls let me know what u think..

regards,

Amey

Former Member
0 Kudos

Invalidating node #2 or #3 has no effect on node #1, thus the drop-down #1 selection (=lead selection of node 1) will stay unchanged.

Armin

Former Member
0 Kudos

Dear Amey,

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute("DropDownFieldContextName");

// DropDownFieldContextName is a context attribute ( could be of string type also) that is bound to the dropdown box at design time.

ISimpleTypeModifiable objType = attributeInfo.getModifiableSimpleType();

IModifiableSimpleValueSet valueSet =

objType.getSVServices().getModifiableSimpleValueSet();

// valueSet.put("key","value");

valueSet.removeKey("key"); // Enter key to remove in double qoutes

Write this code in the onselect function of the first dropdown

You can get the key to delete from context attribute bound to first dropdown.

Tell me if you want more information.

Regards,

Mayuresh

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Edited by: Armin Reichert on Dec 28, 2007 12:46 PM

Former Member
0 Kudos

Hi,

Populate the first drop down when the screen is initialized

Try to populate the other drop downs from the onSelect event of the first Dropdown by key.

OR

Populate all the drop down when the screen is initialized

OnSelect try to remove it from others.

Regards

Ayyapparaj