in GUI Development by

We're using vertical lists for menu selections in our application, with only one item on display. It is working well for user selections using up/down scrolling and SlideTouchHandler. At the end of the interaction, the SlideTouchHander's OnEnd handler obtains the index number of the selected item and stores it in property ItemNum:

var int32 x = VerticalList.Bounds.x1;
var int32 y = VerticalList.Bounds.y1;

var int32 itemNo = VerticalList.GetItemAtPosition(point(x,y));  

// If the item is valid ...
if ( itemNo >= 0 ) {
  VerticalList.SelectedItem = itemNo;   // index is 0 based
  ItemNum = itemNo + 1;                 // display is 1 based

var Utility::TouchMenuItem itemView = (Utility::TouchMenuItem)VerticalList.GetViewForItem(ItemNum-1);

The selected ItemNum is then stored in an array of user selections. The problem arises when we need to restore the setting to the menu. So far, I've been unable to figure out how to get the VerticalList to scroll to and display an arbitrary item number. The code in OnSetItemNum is as follows:

pure ItemNum = value;

if (ItemNum > 0) {
  var Utility::TouchMenuItem itemView = (Utility::TouchMenuItem)VerticalList.GetViewForItem(ItemNum-1);
  if (itemView != null)
    itemView.Background.Visible = true;

But the call to GetViewForItem(ItemNum-1) always returns null. The documentation for GetViewFor Item() indicates that "the method may return 'null' when asking for the view corresponding to an item lying outside the visible area of the list." So, this is obviously not going to work for items not on display. But, as I said, I've been unable to come up with a workable alternative, and none of the list examples for Vertical/Horizontal lists (they are actually identical except for the list orientation) displays the action that I require.

Any suggestions as to how to select an item not on display are greatly appreciated.

1 Answer

+1 vote

Hello Donald,

it is difficult to say, why the method GetViewForItem() returns null in your application case. Maybe the index is not correct or you are calling the method in context of the OnLoadItem slot method? Please see the hints in the chapter Access list items and views.

Generally for typical application cases the approach of using GetViewForItem() is not really necessary. This method exists to satisfy sophisticated optimization cases. If you want to scroll the list to a particular item and select it, see following documentation:

Scroll the list items. (Especially note the method EnsureVisible())

Select an item within the list.

Does it help you?

Best regards

Paul Banach

Sorry for the tardiness in replying---I was diverted to other issues and it took a while to get back to this.

Yes, your reply was very helpful and solved my problem. EnsureVisible() was the key. I now recall coming across this when I was studying your documentation. Later, however, when I realized that I'd need to be able not only to obtain the current value of itemNo for the VerticalList, but also be able to set the value, I looked first at the documentation for Mosaic class Core::VerticalList. And GetViewForItem() seemed a reasonable choice. But your comments and suggestion got me back on target.

Thanks for your timely response; and, again, my apology for my own untimely reply.

Best regards,


Embedded Wizard Website | Privacy Policy | Imprint