How to get objective choice field selected index in Blackberry - blackberry

I have to display items in objective choice Field,based on selected value i have to display another objective choice field how can i do that.How to get selected index value in objective choice field in blackberry.
Thank You

Say you have an ObjectChoiceField myCombo;
which have values from an array.
String myValues [] = {"a","b","c"};
myCombo.setChoices(myValues);
you can get the selected index by using method:
int index = myCombo.getSelectedIndex();
and further if you want the selected value. You would use something like:
String selectedValue = myValues[myCombo.getSelectedIndex()];
See documentation for further reference.

Related

SelectItem with property multiple select

I´m using the SelectItem component with configuration:
private SelectItem nElementsCombo;
nElementsCombo = new SelectItem();
nElementsCombo.setMultiple(true);
nElementsCombo.setMultipleValueSeparator("|");
In the combo the elements selected are shown item_selected_1|item_selected_2|item_selected_3
but when I do:
nElementsCombo.getValueAsString()
Return item_selected_1,item_selected_2,item_selected_3 and I´d like item_selected_1|item_selected_2|item_selected_3
How can I solve this?
from the javadoc :If this item is displaying multiple values, this property will be the string that separates those values for display purposes. Display purpose
I don't catch it, can you replace in your returned string the comma by the pipe ..... !!!
As per Alain's answer, MultipleValueSeparator is only for display purpose.
Means, when you select multiple values from picklist & then when the picklist is hidden on blur (focus lost) of multi select item, the selected values are displayed as a string separated by comma(default). This display can be changed by MultipleValueSeparator. But not the one you get by multiSelectItem.getValueAsString().
Also I don't think, there's any provision in SmartGWT API which fulfills your requirement, as of now.

Smartgwt selectitem key value issue

I have a SelectItem which I fill through a Map that has this combo is within a listgridfield, so good up there, but when I select any item in the combobox instead of get the description or value of the map puts the key in the listgridfield.
How I can do to make me set the value instead of key? now I tried to do with AddChangeHandler but has not worked.
I got the next code:
final ListGridField measureField = new ListGridField(CdmsConstants.MEASURE_ABB, CdmsConstants.CMB_MEASURE_TITULO, 100);
final SelectItem measureComboBox = new SelectItem();
measureComboBox.setDefaultToFirstOption(false);
measureComboBox.setName(CdmsConstants.MEASURE_ABB);
measureComboBox.setTitle(CdmsConstants.CMB_MEASURE_TITULO);
measureComboBox.setDefaultValues(CdmsConstants.CMB_DEFAULT_VALUE);
measureComboBox.setType("comboBox");
measureComboBox.setVisible(true);
measureComboBox.setValueMap(result);
measureComboBox.setValidateOnExit(true);
measureField.setEditorType(measureComboBox);
In the measureComboBox When i put the variable result (that is a Map) and click to any item of the combo the value that shows into the combo box is the key of the linckedhashmap and no the value of the item... how can i make to change this?
Thanks a lot.
If you use a datasource instead of LinkedHashMap, then you can use setValueField method of SelectItem instance. but in this case MAY you can use setValueFormatter method of your SelectItem object.
I had the same/similar problem, my solution that can be seen here ListGrid.setEditorCustomizer in SmartGWT was to use a datasource for the SelectItem and then implemented my own CellFormatter

How to get the selected text from a system.web.mvc.selectlist

I have a system.web.mvc.selectlist when I use .selectedvalue it gives me the value as expected however I use an int ID as the value and would like to get the display text instead.
Update
I've created a selectlist and I'd like to retrieve the selected text on the next line of code. I.e.
SelectList sl = new SelectList(items, "id", "name", 10);
String txt= sl.selectedvalue.text;
That last line is where I am stuck. I'm looking to get the name field for the item with id 10. Ideally without looking up in the db as I want a generic function I can use on all select lists.
I don't think this is possible since the text isn't passed back to the server in a post, only the value is. I can think of two ways to get it though:
Query the database with the value to get the text.
Set the text in a hidden field on the client side before posting the
form. You can do this with jQuery for example.

ListBox gets wrong selected value, how can i get the correct value?

I have a listbox that has the following items and values right now.
Items, Misc. Charge/Taxes/Labor Charges
Value, 50.00/50.00/100.00
The problem is when i select the taxes item, it will turn it into Misc. Charges because they have the same value. Is it possible to have the listbox get the correct item and value if the values are the same??
Thank you!
Use the value attribute as the unique id (miscCharge, Taxes) and the text attribute as what is displayed to the user (50.00, 50.00).
<asp:ListItem value="item1" Text="50" Selected="True"></asp:ListItem>
<asp:ListItem value="item2" Text="50"></asp:ListItem>
ListItem selectedItem = list1.SelectedItem;
string id = list1.SelectedItem.Value;
string text = list1.SelectedItem.Text;

Add empty value to a DropDownList in ASP.net MVC

I'm building a data entry interface and have successfully bound the columns that have reference tables for their data using DropDownList so the user selects from the pre-configured values.
My problem now is that I don't want the first value to be selected by default, I need to force the user to select a value from the list to avoid errors where they didn't pick that field and by default a value was assigned.
Is there a more elegant way of doing this than to add code to include an empty value at the top of the list after I get it from the database and before i pass it to the SelectList constructor in my controller class?
The Html helper function takes a 'first empty value' parameter as the third argument.
<%=Html.DropDownList("name",dataSource,"-please select item-")%>
You can also use this way:
dropdownlist.DataTextField = ds.Tables[0].Columns[0].Caption;
dropdownlist.DataValueField = ds.Tables[0].Columns[1].Caption;
dropdownlist.DataSource = ds;
dropdownlist.DataBind();
dropdownlist.Items.Insert(0, new ListItem("Select ...", string.Empty));

Resources