Hi
I have a datagridview in a windows C# application and i am allowing a user
to select items from the datagridview.
I allow the user to copy the selected items to the clipboard and then if
they chose, to past to the notepad application.
But the items that are selected seem to be pasted in the reverse order than
the user selected them - for example if the user selected items 1 3 5 then
order of the items in the notepad will be 5 3 1.
the code i use is below:
string counter = dgMainView.Sele ctedRows.Count. ToString();
foreach (DataGridViewRo w row in dgMainView.Sele ctedRows)
{
sb.AppendFormat ("{0} ", row.Cells[3].Value);
sb.AppendFormat (" /* {0} - Wave {1} */", row.Cells[1].Value,
row.Cells[2].Value);
sb.Append(Envir onment.NewLine) ;
}
if (counter != "0")
{
Clipboard.SetDa ta(DataFormats. Text, sb.ToString());
// Initializes the variables to pass to the MessageBox.Show method.
string message = counter + " rows copied to clipboard.\nWou ld you like to
open Notepad\nin order to paste these items?";
string caption = "Clipboard" ;
MessageBoxButto ns buttons = MessageBoxButto ns.YesNo;
MessageBoxIcon icons = MessageBoxIcon. Information;
// Displays the MessageBox.
DialogResult OpenNotePad;
OpenNotePad = MessageBox.Show (this, message, caption, buttons, icons);
if (OpenNotePad == DialogResult.Ye s)
{
string file = Path.GetTempFil eName();
StreamWriter sw = new StreamWriter(fi le);
sw.Write(sb.ToS tring());
sw.Close();
Process.Start(" Notepad", file); ;
}
}
else
{
}
Can someone explain why the data is pasted in reverse order or suggest an
alternative way that keeps the order?
Thanks
Doug