Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Posts: 8
Registered: ‎02-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: no

How to show a listview with the given focus?

I try set focus to the listview. I would like to see the data from the listview to show from the 10th position. How do it?Thanks!

Highlighted
Developer
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810
My Carrier: Verizon

Re: How to show a listview with the given focus?

This should work....

 

lv.scrollToItem([0,9], 0x0); //To scroll the list view to the 10th pos
lv.select([0,9], true); //To mark the row as selected

 

Basically you need to specify the index path of the desired row

New Contributor
Posts: 8
Registered: ‎02-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: no

Re: How to show a listview with the given focus?

Thanks, dishooom!

I don't understand why it for me doesn't work. I try it:

***

ListView {
id: listview
****
onCreationCompleted: {
listview.scrollToItem([0, 9], 0x0);
listview.select([0, 9], true);
}

it doesn't work (

Where must i set these fields?

 

Thanks!

Developer
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810
My Carrier: Verizon

Re: How to show a listview with the given focus?

You can set the scroll position in the onDataLoaded event of DataSource, something like this.. .

                        DataSource {
                                    id: dataSource
                                    
                                    source: "Gb.sqlite"
                                    query: "select * from Country "
                                    
                                    onDataLoaded: {
                                        
                                        grpDataModel.clear();
                                        grpDataModel.insertList(data);

                                        lv.scrollToItem([0,9], 0x0); 
                                        lv.select([0,9], true); 
             
            }

 

..this is the case if your list view has a header.... in case it doesn t have one ,... be careful to set it as

 

 lv.scrollToItem([9], 0x0); 
 lv.select([9], true); 

 

-Dishooom


New Contributor
Posts: 8
Registered: ‎02-27-2013
My Device: BlackBerry 10 Dev Alpha
My Carrier: no

Re: How to show a listview with the given focus?

I do not have DataSource object (

I use this code:

***
ListView {
     id: listView
     objectName: "listView"
     visible: true
     horizontalAlignment: HorizontalAlignment.Center
     verticalAlignment: VerticalAlignment.Top
     dataModel: XmlDataModel {
         source: _qDownloader.loadModel // emit "data/source.xml"
     }
     listItemComponents: [
         ListItemComponent {
             type: "component1"
             LeftComponent {
                 name: ListItemData.mName
                 date: ListItemData.mDate
                 checked: ListItemData.mChecked
             }
         },
         ListItemComponent {
             type: "component1"
             LeftComponent {
                  name: ListItemData.mName
                  date: ListItemData.mDate
                  checked: ListItemData.mChecked
             }
         },
                            
         ****                 
        ]
    }
}
***

Is there any way to set these fields to the my code?

Thanks!