BListView problematic

Hello everyone,

I’m stuck in my code, on a call to the function CurrentSelection() from BListView.

This function is supposed to return an index corresponding to that of the selected item. But the value I get is not the one I would like to have (something like ‘17680’ instead of 'what i suppose to obtain : ‘4’, namely, the one I can retrieve using ItemAt(i) from BListView.

i = BlistDir->CurrentSelection(i);
								
std::cout << "i = " << i << std::endl;
								
bListIt = BlistDir->ItemAt(i);

BrwEl* Eli = (BrwEl*)BlistDir->ItemAt(i);

Does anyone know this part of the Haiku api ? and may help me ?
I’m really embarrassed and I hope I’m not bothering you with my newbie problems.

1 Like

BListView::CurrentSelection() yields the index of the first selected item in the list relative to the passed in index. To get the index relative to the start of the list pass in 0 or don’t pass anything in. The index parameter is used to iterate over all selected items in the list. See the BeBook for more information:

Edit: 17680 indicates you may be passing a pointer to a list item in as i instead of an index to a list item which almost certainly is not a valid index in the list.

4 Likes