Lets assume that the view is the following:
The Code behind is the following:
And the MainViewModel code is:
Run the code. Then Press Ctrl + A, in order to select all cells.
Then click on the Button.
You should get an exception (The grid view code tries to access a column with index that does not exist).
If I remove the cellInfo null check, and just write:
var selectedCells = (sender as RadGridView).SelectedCells;
Then I'll get that few cells in the SelectedCells are nulls (I might get that the firstCell, or the lastCell are nulls).
Now for another interesting bug:
Restart the code.
Select the first cell (upper left corner). The code shows Row = 0 and Col = 0 --> Good.
Now Click the button.. The selection is cleared...
Now Select the first cell again. The code shows Row = -1, Col = 0. (WTF?)
Now, any cell that you will select on the first row will give you that result. But if you select a cell from a different row, and then reselect a cell from the first row, then the problem is fixed.
Btw, getting the Item from the Added cells and checking its row index does give the correct result, but what I'm trying to do is to have the user have only 1 selected region (A rectangle of selected cells), so I can have a from row, from cell, to row, and to cell information.
So, in my code, I also clear selection in Grid PreviewMouseLeftButtonDown.
Any other suggestions of having only rectangular selection will be welcome (since right now, clicking on blank area, or clicking the scrollbar also clears the selection).
Furthermore, any suggestions on how to get the correct selected region will be welcome.