Can anybody help me to get the index of items selected in a list view.
I was trying in JAVA FX but all my work went in vain.
Use the selectionModel to get a list of those indices:
ListView listView = ...
ObservableList<Integer> selectedIndices = listView.getSelectionModel().getSelectedIndices();
this will capture the selected line into a variable for you to use at will:
int selectedIndex = listView.getSelectionModel().getSelectedIndex();
Related
Is there a method on a <asp:DropDownList> that is equivalent to the OnItemDataBound on Repeaters?
The reason is I want to check each value before putting it in the drop down list.
Nothing similar to OnItemDataBound which will give you an item context.There are events like OnDataBound which will get triggered when it reaches binding.
Your reason for asking this event is for enriching the row instead to filterout, which would not have helped you even with this event.
The best option to solve your question
The reason is I want to check each value before putting it in the drop
down list.
is to do some thing like the following pseudo code
this.YourDropDownList.Items.Clear();
var lst = new List<ListItem>();
var yourCollection= <YOURCollection after Apply Linq Conditions check>
foreach (var obj in yourCollection)
{ //loop and add
this.YourDropDownList.Items.Add(new ListItem {Text = obj.Prop1, Value = obj.prop2});
}
I'm trying to have a ComboBox list the contents in sorted order. I've come up with one solution, but it still has some issues.
final ObservableList<String> oal = FXCollections.observableArrayList();
final SimpleListProperty<String> slp = new SimpleListProperty<String>(oal);
final SortedList<String> sl = new SortedList<String>(slp, (string1, string2) -> {
return string1.compareTo(string2);
});
final ComboBox<String> comboBox = new ComboBox<String>();
comboBox.setItems(sl);
I can add values to OAL or SLP.
oal.addAll("cccc", "aaaa", "bbbb");
slp.addAll("ffff", "dddd", "eeee");
But if I try to add values to SL, it fails.
sl.addAll("iiii", "hhhh", "gggg");
Exception in thread "main" java.lang.UnsupportedOperationException
So of course any attempts to add values to comboBox also fail. Does anybody know a way to fix this, or is there a totally different approach to sorting the contents of the ComboBox?
I appreciate any help here.
I'm using Java 8u5.
Can't you just add items to the underlying list instead of the sorted list?
final ObservableList<String> comboBoxItems = FXCollections.observableArrayList();
final ComboBox<String> comboBox = new ComboBox<String>();
comboBox.setItems(new SortedList<String>(comboBoxItems, Collator.getInstance()));
And then just always add items to comboBoxItems.
I'm adding this as an answer as I don't have enough stackoverflow reputation to comment.
Be aware that there is currently (Java 8u92 and probably before) a bug JDK-8087838 that causes extra unwanted Combobox OnAction events to fire when adding items to an editable combobox when a SortedList is used instead of an ObservableList. This bug makes it difficult to properly code for the combobox events, so I suggest not using a SortedList until the bug is fixed. See also this stackoverflow question.
I Want to get the total count of rows fetched when the user selects/checks SelectAll checkbox in Extjs grid.
Pls let me know how to do this.
To get all the rows in a grid, use:
store.getRange();
To only get the selected rows use:
var selectionModel = grid.getSelectionModel();
var selected = selectionModel.getSelection();
You can use like,
var sm = grid.getSelectionModel();
var Selected_record_count = sm.getCount()
Explanation;
getSelectionModel() - Returns the selection model being used and creates it via the configuration if it has not been created already.
getCount() - Returns the count of selected records.
I have a datagrid. In this datagrid I have a combobox item editor. This datagrid also has multiple columns where a user inputs numbers in each column. These numbers are then calculated by formula where the sum is posted in the "total" column. In this combobox there are two options for the user to choose from and each option has a different formula for calculating the inputted numbers. What I want is for when a user chooses "option 1" one formula is used to do the calculation, when "option 2" is chosen by the user then formula two is used to the calculation.
Here's an example:
Combobox Option 1 (formula 1) is chosen by user = (Column2 - Column1) x column3 = "total" column
Combobox Option 2 (formula 2) is chosen by user = (Column1 - Column2) x column3 ="total" column
I realize you would use a conditional such as "if else" statement, but im just not sure how to do it. I've been trying to implement this for a while with no success so any help or suggestions would be greatly appreciated.
Listen for the combobox's change event and implement the formula calculation in the change event handler according to the selectedItem.
public function changeEventHandler(event:Event){
if(ComboBox(evt.target).selectedItem.label == forumla1) {
//logic
} else if(ComboBox(evt.target).selectedItem.label == formula2) {
//logic
} else {
//do nothing
}
}
That's interesting. You cannot add listeners directly because item renderers are reused and don't keep their identity. Some thoughts on problem:
when combobox' selected item is changed, it dispatches bubbling event EVENT.CHANGE.
you should make custom renderer for computed columns. When renderer is added to datagrid (use EVENT.ADDED), use owner property (that should be datagrid) to add listener to EVENT.CHANGE. Check that you getting that event (change renderer's text to "got it", for example).
now all your computed cells are getting notification when any combobox changed. First, you need to discard events from rows other than item's row. To do that, renderer needs to know its own rowIndex - see Creating custom List renderers, item 2. Compare rowIndex and datagrid's selected index to bail out if they don't match.
now you have combobox in event.target, rowIndex and datagrid - that should be enough to get needed formula and data from datagrid's columns.
HI..
i want to add elements dynamically to listview in QT for symbian OS, i have set of delegate methods associated with listview.
if i add elements statically, the control comes to delegate methods, and view is perfect.
but if i add dynamically, control is not at all coming to delegate methods.
i don't no how to do it. ill place here some sample code, that how i am adding elements.
this is how i am setting the view,
MylistView = new QListView();
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect clientRect = desktopWidget->geometry();
MylistView->setMinimumSize(QSize(clientRect.width()-7,clientRect.height()-1));
MylistView->setViewMode(QListView::ListMode);
MylistView->setMovement(QListView::Free);
MylistView->setItemDelegate(new ItemDeligate(MylistView));
MylistView->setSelectionMode(QAbstractItemView::SingleSelection);
bool val =GreenPixmap.load(":/new/prefix1/temp/test.png");
ListModel = new QStandardItemModel();
ListModel->appendColumn(ItemList);
MylistView->setModel(ListModel);
Listlayout.addWidget(MylistView);
Listlayout.addWidget(MylistView);
this->setLayout(&Listlayout);
AddItemMenu = new QAction("Add",this);
menuBar()->addAction(AddItemMenu);
val = connect(AddItemMenu,SIGNAL(triggered()),this,SLOT(addItem()));
This is how i am adding dynamically when the click event occurs, (i.e dynamically adding items)
QStandardItem *Items = new QStandardItem(QIcon(GreenPixmap),"Avatar");
Items->setData("WAKE UP",ItemDeligate::SubTextRole);
ItemList.append(Items);
ListModel->appendColumn(ItemList);
please suggest me, what mistake i am doing in adding elemetns
I just made this quick example in my app, it's working, maybe it will gibe you an hint :
QStandardItem* Items = new QStandardItem("Avatar");
QStandardItemModel* ListModel = new QStandardItemModel();
ListModel->appendRow(Items);
listView->setModel(ListModel);
In summary, you should simply append a row on your model ! It should fix your problem !
If I missed something, let me know !