javafx tableView getting previous Item - javafx

Hey im doing a Playlist for Music and im doing the previous and Forward button but i dont know how i get the file before/ after the current one. I use this for the current
play(tableView.getSelectionModel().getSelectedItem());

For previous, use
int currentIndex = tableView.getSelectionModel().getSelectedIndex();
tableView.getItems().get(currentIndex - 1);
and similarly for next. You will want to add checks for the range (i.e. don't get the previous item if currentIndex == 0, and similarly for next).

Related

How to move programmatically to selected row in Qt?

I use QTreeView and QSortFilterProxyModel
// Here I determine the index, that was saved before (_lastAddObjectIndex - QModelIndex)
QModelIndex next_index = _proxyModel->index(_lastAddObjectIndex.row(), 0);
// Here I select the row programmatically, and after that I'd like to move to that row (because table might have many rows)
view->selectionModel()->select(next_index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
I assume by moving, you mean scrolling. If so, you can achieve this by using this API:
view->scrollTo(next_index);
You can even change the scroll hint if you pass a second parameter to the method. This depends on whether you are happy with the default value, which just makes sure that the item is visible.
You can refer to the documentation for fine-tuning this behaviour further in case you need to.

How to check whether the new line is created but not saved yet

Which FormDataSource method to use to determine that the record is not saved yet?
i.e.
I mean when my grid line is in this situation I want my mennuItemButton to throw the error.
Thanks...
You can check the RecId == 0, but in your case it would be simpler to set the NeedsRecord attribute of the menu item. This will disable the button if there is no active record.

How to get this QTableWidget to display items?

I have a QTableWidget and I can't get anything to show up in it.
The following appears in the constructor of the main window:
ui->tableWidget->setItem(0,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(0,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(0,2,new QTableWidgetItem("Item3"));
When I run the application, the table widget shows up, but the items do not.
I tried adding ui->tableWidget->insertRow(0); before the above code, but it didn't work.
Aha! I figured out what was going on... I needed to tell the control the number of rows it should have:
ui->tableWidget->setRowCount(2);
Example code:
//this will give the present number of rows available.
int insertRow = ui->tableWidget->rowCount();
//insert the row at the bottom of the table widget - using.
ui->tableWidget->insertRow(insertRow);
//After a new row is inserted we can add the table widget items as required.
ui->tableWidget->setItem(insertRow,0,new QTableWidgetItem("Item1"));
ui->tableWidget->setItem(insertRow,1,new QTableWidgetItem("Item2"));
ui->tableWidget->setItem(insertRow,2,new QTableWidgetItem("Item3"));

ExtJs / Sencha : how to highlight a grid row after insert?

I want to create such a grid:
http://www.sencha.com/deploy/dev/examples/grid/edit-grid.html
Actually I already did, but I want to highlight the last inserted row of my grid (in extjs this is the function highlight(), which does a yellowfade on the element).
I didn't actually succeed in doing this... my problem is that I can't get the row I just inserted, and thus obviously I can't highlight it.
Any clues?
Thanks in advance
You only need to do this (here for row number one):
var row = grid.getView().getRow(0);
Ext.get(row).highlight();
It's that easy.
The code has
store.insert(0, p);
So don't you just highlight row zero immediately after that statement?
yes sorry for answering too late,
use Ext.grid.RowSelectionModel and than use selectLastRow function u can easily will be able to point it out :)
Ext.data.store has a add listener which is passed an index at which records were inserted
add : ( Store this, Ext.data.Record[] records, Number index )
This would go inside of your add/create button event. The code this.getSelectionModel().select(0); will highlight the first row since we inserted into position 0, we are selecting position 0. This code works with ExtJS 4.2.0.
var rec = Ext.create('App.model.GridModel', {
id: '123',
name: 'ABC'
});
this.store.insert(0, rec);
this.getSelectionModel().select(0);

Change item sortorder in gridview - LINQToSQL

I've got a gridview with a list of categories. In the database (MSSQL2008), the category table has a SortOrder(INT) NULL field.
Currently categories are retrieved using:
Galleries.DataSource = From G In DB.GalleryCategories Order By G.SortOrder, G.Name
Now, what I need to be able to do is add "Move Up" and "Move Down" buttons to each row to allow the user to sort the items in an arbitrary way.
My initial thoughts are along the lines of:
Identify ID of selected item.
Identify ID of item before/after selected item.
Swap of identified items in the DB SortOrders.
I would then have make the sortorder NOT NULL and make sure it's initialised to a unique number
I'd appreciate any alternative suggestions / comments on this approach
Many thanks
I have generally seen it done this way, and have done it myself
SortOrder is an int
Each item increases by 10 (so, 10,20,30,40) or suitable increment
To move an item up, subtract 15
To move an item down, add 15
To insert an item, take the target and add/subtract 1
Apply a NormalizeSort() routine which resets the values to even intervals
10,20,25,30,40 => 10,20,30,40,50
That makes it all pretty simple, since inserting something above something else is just:
list.Add( New Item(..., target.SortOrder +1) )
list.NormalizeSort()
// or
item.SortOrder += 11, etc
If you want to make it a decimal, then you can just make it all sequential and just add .1, etc to the sort order and re-normalize again.
// Andrew
I believe
Galleries.AllowSorting = true;
would be far enough ;)

Resources