populate combobox code:
ComboBox getCategoryComboBox = new ComboBox();
searchOptionForm.add(getCategoryComboBox);
getCategoryComboBox.setUIID("TextField");
getCategoryComboBox.addItem("Choose Category");
for (Map<String, Object> entry : alacc.responseCategory) {
String categoryName = (String) entry.get("name");
String categoryId = (String) entry.get("id");//how to set this to combobox item
getCategoryComboBox.addItem(categoryName);
}
categoryId is taken from for loop above, how to set it in each combobox items? I need to get the categoryId of each selected combobox item, how can i get this?
You have several ways to do this.
One way is to just do:
getCategoryComboBox.addItem(entry);
Which would provide you the full entry on getSelectedItem() effectively solving that problem.
To make the name render properly though you would need to do this:
cb.setRenderer(new DefaultListCellRenderer<Object>() {
public Component getCellRendererComponent(Component list, Object model, Object value, int index, boolean isSelected) {
if(value instanceof Map) {
value = ((Map)value).get("name");
}
return super.getCellRendererComponent(list, model, value, index, isSelected);
}
});
Notice you will also need to define the theme constant otherPopupRendererBool to false for this to work properly.
Related
I am trying to get selected item text. I used this below code
MessageBox.Show(listBoxColumnHeaders.SelectedItems);
Output
Devexpress.XtraEditors.BaseListboxControl+SelectedItemCollection
But my text is Country
Update
I add listbox items from another class. That class called FilterColumnHeader using below code
FilterControl fc = Application.OpenForms.OfType<FilterControl>().SingleOrDefault();
List<FilterColumnHeader> headers = new List<FilterColumnHeader>();
while (rd.Read())
{
headers.Add(new FilterColumnHeader { typeOfHeader = rd["type"].ToString(), columnHeadersName = rd["AsHeading"].ToString() });
}
fc.listBoxColumnHeaders.DisplayMember = "columnHeadersName";
fc.listBoxColumnHeaders.ValueMember = "typeOfHeader";
fc.listBoxColumnHeaders.DataSource = headers;
Now When I try to print using this below code,
MessageBox.Show(""+ listBoxColumnHeaders.SelectedItems[0].ToString());
It is showing in message box like below
`ProjectName.FilterColumnHeader`
The SelectedItems property returns a collection of selected objects. All you need to do is to cast the required object to your type:
var filterColumnHeader = (FilterColumnHeader)listBoxControl.SelectedItems[0];
I don't know if you found an answer but this works for me :
StringBuilder list = new StringBuilder();
foreach(var item in listBoxColumnHeaders.SelectedItems)
{
list.AppendLine(item as string);
}
MessageBox.Show(list.ToString());
This is not exactly an question, better to say - it's an answer with a little question: is there a better sollution? :)
Suppose you have a grid which contains some rows.
In each row you want to put a radio button, and only one radio button can be selected in the grid (each row has one radio button).
This radio button should be used not only to display selected row, but also to select a row by clicking radio button.
Selection is based on a table's field, which contains 1 for selected and 0 or null for all other rows.
Here is a short guide of achieving it:
(the obvious part)
add a column with a radiobutton:
<af:column headerText="#{bindings.DocsignersliteView2.hints.Isactual.label}"
id="c14" align="center">
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
autoSubmit="true">
</af:selectBooleanRadio>
</af:column>
where Isactual - is the field in the table, which containts 1 for selected item and null for all others
Method onActual should be implemened to change values of the field Isactual in the table.
it appears to not work. Now it shows an actual row, but doesn't work when I select another radio button.
Naturally I tried to create ValueChangeListener, but never succeded - it didn't work correctly.
Ok, let's try to invert "onClickListener", as selectBooleanRadio doesn't posess such an attribute:
let's add clientlistener, javascript and server listener:
<af:resource type="javascript">
function onClickRadio(actionEvent) {
var comp = actionEvent.getSource();
AdfCustomEvent.queue(comp, "IsactualClickEvent",
{},
true);
actionEvent.cancel();
}
</af:resource>
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
autoSubmit="true">
<af:clientListener type="click" method="onClickRadio"/>
<af:serverListener type="IsactualClickEvent"
method="#{viewScope.signerBean.onActual}"/>
</af:selectBooleanRadio>
it almost works, but there is one more 'tiny' detail: a field with 1 and 0 values (or 1 and null) - is not exactly the same as boolean, so this selectBooleanRadio needs a converter.
So we should create a class implementing converter:
public class BooleanDecimalConverter implements Converter {
public BooleanDecimalConverter() {
super();
}
#Override
public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) {
if (string == null || string.isEmpty())
return null;
return "true".equals(string) ? BigDecimal.valueOf(1) : BigDecimal.valueOf(0);
}
#Override
public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) {
if (object == null)
return null;
String result;
if (object instanceof Boolean){
result = object.toString();
}
else if (object instanceof BigDecimal) {
BigDecimal num = ((BigDecimal)object);
result = num.compareTo(BigDecimal.valueOf(1)) == 0? "true" : "false";
}
else {
result = "false";
}
return result;
}
}
then register the custom converter in the application's JSF configuration file (faces-config.xml):
<converter>
<converter-id>custom.BooleanDecimalConverter</converter-id>
<converter-class>common.utils.converters.BooleanDecimalConverter</converter-class>
</converter>
and at last we can add a converter attribute to af:selectBooleanRadio:
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
converter="custom.BooleanDecimalConverter"
autoSubmit="true">
<af:clientListener type="click" method="onClickRadio"/>
<af:serverListener type="IsactualClickEvent"
method="#{viewScope.signerBean.onActual}"/>
</af:selectBooleanRadio>
What we have now:
A grid with rows, radio buttons show an "active" row and allow user to change "active" row immediately as he clicks the radio button.
I've a listener on cellClick, I get the selected Record but I can't find a way to understand if this record is checked
Method ListGrid.isSelected(ListGridRecord) returns true if row is selected, not if is checked
My Code:
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
listGrid.addCellClickHandler(new CellClickHandler() {
#Override
public void onCellClick(CellClickEvent event) {
if(event.getColNum() == 0 && idMenu != null){
boolean isChecked = event.getRecord().???;
if(isChecked)
....
else
....
}
I've tried also with event.getRecord().getAttributeAsBoolean("_checkField") with no success...
I found a simply solution...
My task is solved using a special boolean field in the DataSource named, for example, "checked"
In ListGrid I've a field "checked", and with a RecordClickHandler I can manage check or uncheck event.
DataSource code:
DataSourceBooleanField checkField = new DataSourceBooleanField("checked");
ListGrid code:
listGrid.addRecordClickHandler(new RecordClickHandler() {
#Override
public void onRecordClick(RecordClickEvent event) {
Record rec = event.getRecord();
boolean checked = rec.getAttributeAsBoolean("checked");
if(checked){
...
}else{
...
}
rec.setAttribute("checked", !checked);
catPgrid.saveAllEdits();
catPgrid.refreshFields();
}
});
ListGridField checkField = new ListGridField("checked", "Sel");
Maybe getSelectedRecords() method would help you!
Here is an API reference: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/grid/ListGrid.html#getSelectedRecords()
Definitely this will provide all records which are selected (using checkbox) but there should be some values which you could use for identifying each record uniquely!
I can't figure out how to programmatically select items in checkboxlist.
This method of cource doesn't compile, but I want to show you what a result I want to get.
public ColumnsSelector(Dictionary<string, bool> dataPropertyNames)
: this()
{
foreach (var item in dataPropertyNames)
{
checkedListBox1.Items.Add(item.Key);
checkedListBox1.Items[checkedListBox1.Items.IndexOf(item.Key)].Checked = item.Value;
}
}
How do you force with this problem?
Use CheckedListBox.SetItemCheckState:
checkedListBox.SetItemCheckState(checkedListBox1.Items.Count - 1, CheckedState.Checked);
which works for checked, unchecked, and indeterminate. You can also use CheckedListBox.SetItemChecked:
checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);
checkedListBox1.Items.Add(item.Key);
checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, item.Value);
or just
checkedListBox1.Items.Add(item.Key, item.Value);
I have a treeview that is bound to a collection and each item in the collection is bound to another collection. (using hierachle data templates)
I would like to use the collection view .Filter event handler to search the tree.
The problem is that I need multiple collection views.
What would be the best way to filter the tree view items for example by a search word? I can do this with a single binding of a collection, but once there are collections within collections I have trouble.
The easiest way I found to do this is create a SearchFilter Property
public string SearchFilter
{
get { return _searchFilter; }
set
{
_searchFilter = value;
OnPropertyChanged("MyTreeViewBoundCollection");
}
}
You bind the search filter to a text box, and everytime the search text box changes you notify that the collection has changed
<TextBox Text="{Binding Path=TemplateDataSchema.SearchFilter, UpdateSourceTrigger=PropertyChanged}"/>
Once the change has occured on the SearchFilter, The WPF binding system will requery the Collection Property, which can then be filtered down
public ObservableCollection<Category> MyTreeViewBoundCollection
{
get {
if (_searchFilter.Trim().Length < 1)
return myObject.Categories;
else
{
ObservableCollection<Category> cats = new ObservableCollection<Category>();
string searchText = _searchFilter.ToLower().Trim();
foreach (Category cat in myObject.Categories)
{
Category tmpCat = new Category(cat.CategoryName);
foreach (Field field in cat.Fields)
{
if (field.DataDisplayName.ToLower().Contains(searchText))
tmpCat.Fields.Add(field);
}
if (tmpCat.Fields.Count > 0)
cats.Add(tmpCat);
}
return cats;
}
}
}
This will only return the filter collection.