This project is read-only.

Selection issue

May 21, 2009 at 11:51 AM

Hello, everyone, I have a issue involving with selection, here is the situation: I use the below code to move selection up

public void MoveUpOneRow(int rowIndex)
{
if (rowIndex > 1 && rowIndex < RowsCount)
{
//get the current selection state of the current line and previous line
bool curRowSelected = Selection.IsSelectedRow(rowIndex);
bool prevRowSelected = Selection.IsSelectedRow(rowIndex - 1);
Rows.Move(rowIndex, rowIndex - 1);
//move the selection to reflect the change, which is accomplished by exchange the selection state 
//of the current line and previous line
Selection.SelectRow(rowIndex, prevRowSelected);
Selection.SelectRow(rowIndex - 1, curRowSelected);
}
}

It worked as expected, the highlight goes up, and the original line is unselected, except one thing: that is after moving up
the selection, most of the time, the original line can't be selected( well, sometimes it can, which is a puzzle to me ). I believe 
it's a bug which has something to do with focus, but I don't know how to walk around this. Does anyone have a solution?
Or does anyone have encountered this kind of thing.

One more thing, about the code, it's a excerpt of my class which extends the Grid class.


May 22, 2009 at 12:51 PM

For a concrete example, say that we have 3 rows, and now row 3 is selected. Then I run my code and now the selection moved up and row 3 is unselected and row 2 is selected. And now the row 3 can't be selected.

May 25, 2009 at 12:09 PM

I solved this problem by myself. It was because of the focus. I moved the selection but I didn't move the focus accordingly. And now everything works beautifully.