10-23-2012 11:38 AM
I would like to programatically select the next item in a list view. I've not found a simple way to do that. Is there one?
I need to do that in C++, not in QML.
Solved! Go to Solution.
10-23-2012 11:56 AM
If you're using a data model with non-simple index paths (multi-level, rootIndexPath not at , etc) then how you adjust the returned index path may be non-trivial.
10-23-2012 12:01 PM
This is what I want to do, but I tried to look at the variant to understand what it is, but can't really figure it actually.
My data model seems quite simple to me, only one level, a short name, and a url.
Do you have any clue?
10-23-2012 05:18 PM
You'll find your answer here https://developer.blackberry.com/cascades/referenc
ListItem.indexPath - The index path identifying this item in its DataModel.
10-24-2012 07:03 AM
I may have not understood, you're giving me the pages I used as references, and I still found nothing that can help.
If I get the next value in datamodel, it will not necessarly be the next in the list view given the sort order can be different, so I'm not sure how datamodel will help.
If the order is the same, is something like this supposed to work (cause it crashes)?
int idx; // idx in model
entry["name"] = mShortName(); // used as title in the ListView
entry["url"] = mUrl;
idx = m_model->indexOf(entry);
QVariant v = m_model->value(idx);
QVariantList lv ;
mList = mAppPage->findChild<ListView*>("mList");
if ( mList != NULL )
I'm using indexPath only in qml this is what i use to populate my variables (mUrl and mShortName):
_trackManager.select( dataModel.data(selected()).url )
10-25-2012 03:51 AM
This would have been a good solution, but unfortunately this is not really an option.
I'm using ArrayDataModel so that the user can change the list the way he wants.
BTW, I don't understand why the code I wrote to get the next doesn't seem to work:
I know the id of the selected object (it' my idx variable), so at the end of this code, I'm supposed to have the next value in vl.
Am I right with this?
QVariant v = model()->value(idx);
If yes, then as far as I understood what indexPath is,
this code is supposed to select the item in the list:
ListView *list = appPage()->findChild<ListView*>("mList");
if ( list != NULL )
Thanks for the help,
10-25-2012 08:26 AM - edited 10-25-2012 08:29 AM
Just understood what was wrong with the code, and it was really simple.
Here is the code that will work:
QVariant vPath = indexPath;
int idx = vPath.toInt();
QVariant v = idx ; // instead of : v = model()->value(idx);
I was tring to make things far more complicated than they are, and here I detailed all steps but the code can be even easier.
Thanks to those that tried to help me.