UnselectAll() and UnselectAllCells not working

May 16, 2009 at 4:30 AM


I did a call to SelectAllCells() to copy the content of the cells, then when I finishing procesing all cells I made a call to UnselectAll() and/or UnselectAllCells and neither do the trick.

I would also like to know the difference between both methods, UnselectAll() and UnselectAllCells()


Thanks in advance, Ajadex.



May 23, 2009 at 3:53 AM

Make sure you set the intended SelectionMode and SelectionUnit, also check that the SelectAllCells.Count is > 0 before you call into the UnselectAll or UnSelectAllCells. 

For the difference between UnselectAll and UnselectAllCells - the main consideration here is what selection unit {CellOrRowHeader, Cell, FullRow} you use, if you set SelectionMode="Extended" SelectionUnit="CellOrRowHeader", both should work; but if you set the selection unit to either Cell or FullRow, only one of them would work.  <font size="2" color="#0000ff"><font size="2" color="#0000ff">


</font></font><font size="2" color="#0000ff">







May 23, 2009 at 8:25 PM
Edited May 23, 2009 at 8:38 PM

Thank you for your explaination, I solved the problem. However there must be a bug in the datagrid that prevent itself to unselect the cells when the order of the methods call is as below:

dgExport.SelectionMode = DataGridSelectionMode.Extended;
dgExport.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;

ApplicationCommands.Copy.Execute(null, dgExport);
object a = Clipboard.GetData(DataFormats.Text);
string file = "d:\\MyTemplate2.xls";

File.WriteAllText(file, (string)a, Encoding.BigEndianUnicode);