Page 1 of 1

MultiColumnList RowMultiple getNextSelectedItem

Posted: Tue Feb 28, 2006 19:38
by Falagard
Hi guys. I was trying to use MultiColumnList with RowMultiple selection mode and then trying to retrieve the multiple rows that the user had selected and was having problems.

I was doing something like this:

Code: Select all

    CEGUI::ListboxItem* item = mSelectList->getFirstSelectedItem();
   
    if(!item)
      return true;

    for(;item != NULL; item = mSelectList->getNextSelected(item))
    {
      //do something here for selected item
    }


However it wasn't working as I expected. If a user had selected two rows, it was iterating through the first selected row, each item in each column in that row, but then not moving onto the next row. I looked at the source code for CEGUIMultiColumnList::getNextSelected and couldn't see what the problem might be. I'm actualling using the compiled SDK 0.4.1 but I additionally downloaded the source.

To get what I wanted I had to do this:

Code: Select all

    CEGUI::ListboxItem* item = mSelectList->getFirstSelectedItem();

    if(!item)
      return true;

    int colCount = mSelectList->getColumnCount();
    int rowCount = mSelectList->getRowCount();

    for(int row = 0; row < rowCount; ++row)
    {
      for(int col = 0; col < colCount; ++col)
      {
        CEGUI::MCLGridRef gridRef(row, col);
        //get item by grid reference
        item = mSelectList->getItemAtGridReference(gridRef);
        if(item->isSelected())
        {
          //do something here with the selected item
          break; //break out of the column loop
        }
      }
    }



Perhaps this will help others, or you could explain what I was doing wrong.

Clay

Posted: Thu Mar 02, 2006 09:19
by CrazyEddie
Hi Falagard :)

I've not looked at the code yet, but this definitely sounds like some kind of bug.

Thanks for bringing it up, and for the work-around :D

CE.

Posted: Tue Apr 25, 2006 06:21
by Rackle
The problem is with this bit of code within CEGUIMultiColumnList.cpp line 505:

if (start_item != NULL)
{
startRef = getItemGridReference(start_item);
++startRef.column;
}

Let's say the multi column list has three columns and the first two rows are selected. The cycle is started with a NULL, via the call to getFirstSelectedItem(). It will iterate through row 0, columns 0, 1, 2. The problem is that when trying to access the next row the code above will raise startRef.column to 3, which is beyond the capacity of getColumnCount(), which will prevent the code that follows from iterating through the second selected row.

The solution would be to increment the row and reset the column:

if (start_item != NULL)
{
startRef = getItemGridReference(start_item);
++startRef.column;
if( startRef.column == getColumnCount() )
{
startRef.column = 0;
++startRef.row;
}
}


[EDIT] Changed getRowCount() to getColumnCount(), silly mistake.

Posted: Tue May 09, 2006 22:13
by lindquist
I have applied this fix to both 0.4 and 0.5