cancel
Showing results for 
Search instead for 
Did you mean: 

How to select 1st entry in DropDownByKey object

Former Member
0 Kudos

Hello,

My view has a dropdown box that is bound to a data dictionary simple type as described in the help documentation. That works fine.

However, I'd like to have the first entry automatically be selected the first time that the view is opened.

I've found postings on this forum showing how I can programatically select an entry in the dropdown by specifying the value. I don't want to do that because then I'm hardcoding a specific value in my code. I want to be able to programatically select the 1st entry in the list.

Is that possible? If so, can someone point me to some documentation showing how? I can't find anything on this.

Thanks in advance for any help.

David

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi David,

Please close this query if you were able to solve your problem.

If you still haven't got the solution :-

Say you have an attribute 'drop_by_key' mapped to the dropdown by key UI element. Then you can set the first key as selected as



String attributeName = IPrivateMyTestView.IContextElement.DROP__BY__KEY;
IWDAttributeInfo attributeInfo = wdThis.wdGetContext().getNodeInfo().getAttribute(attributeName);

ISimpleType simpleType = attributeInfo.getSimpleType();

ISimpleValueSet valueset = simpleType.getSVServices().getValues();
Object key = valueset.getKey(0);
wdContext.currentContextElement().setDrop_by_key((String)key);

Best Regards,

Nibu.

Answers (2)

Answers (2)

Former Member
0 Kudos

Nibu,

That is EXACTLY what I was looking for. Thanks very much for your help.

David.

Former Member
0 Kudos

hi David,

The attribute which is bound to selected key of the dropdownbykey UI element; set its value to the default value which you want to show when the view is being loaded

For example if sel_att is bound.

wdcontext.currentcontextelement.setsel_att(<default value>)

in doinit solves your problem

Regards

Rohit

Message was edited by: Rohit Radhakrishnan

Former Member
0 Kudos

Rohit,

Thanks for your reply.

As I said in my original post, I am aware of setting it that way. What I don't like about that way is that it requires me to hardcode the default value.

I just want to tell it to select the first entry in the dropdown regardless of what it is. In other words, instead of passing a String value into it I'd like to pass in an index value.

For example, if my dropdown lists cities it may start with "Atlanta" when program is written but eventually "Akron" may be added. That would mean my code would have to change from

wdcontext.currentcontextelement.setCity("Atlanta")

to

wdcontext.currentcontextelement.setCity("Akron")

A better solution would be for me to be able to tell it to select the first entry in the dropdown regardless of what it is.

David

Former Member
0 Kudos

hi David,

Create the simple type using the code

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("<attribute name");

ISimpleTypeModifiable modinfo = attinfo.getModifiableSimpleType();

IModifiableSimpleValueSet valset = modinfo.getSVServices().getModifiableSimpleValueSet();

valset.put(key ,desription)

From where are you getting values in your dropdown.You should set it accordingly.For eg if if it is from vector

if there is are two variables in the element in a vector say A and B

You can access it by creating a java class in containing getter and setter methods().Make an object of it

<Class name> object = (<Class name> )vector.getElementAt(1);

wdcontext.currentcontextelement.set<attribute name>(object.get<A>())

Hope this helps you

Regards

Rohit

Message was edited by: Rohit Radhakrishnan

Message was edited by: Rohit Radhakrishnan