I use the following code to copy the selected row content to the clipboard:
if (grid != null)
{
if (grid.SelectedItems.Count > 0)
{
StringBuilder strGridStrings = new StringBuilder();
for( int i = 0; i <= grid.SelectedItems.Count - 1; i++ )
{
Row row = (Row)grid.GetContainerFromItem(grid.SelectedItems[ i ]);
if (row != null)
{
foreach (Cell gridCell in row.Cells)
{
if (gridCell != null && gridCell.HasContent)
{
strGridStrings.Append(gridCell.Content.ToString()).Append("\t");
}
}
}
strGridStrings.Append("\r\n");
}
string strClipboardString = strGridStrings.ToString().TrimEnd("\t\r\n".ToCharArray());
Clipboard.SetText(strClipboardString);
}
}
This works fine, except if i cahnge the sort order of the rows or columns then the content that gets copied into the clipboard doesn't reflect the user specified order, what's the best way to deal with this?