Hi,
You're creating the order in question yourself, by using this iteration:
foreach (DataGridViewRow row in dgMainView.SelectedRows)
So iterating the other way round should reverse your order:
for (int i = dgMainView.SelectedRows.Count - 1; i >= 0; i--) {
DataGridViewRow row = dgMainView.SelectedRows[i];
....
My personal point of view is as always: the selection order in the
SelectedRows is not something I would rely on anyway. As far as I can see,
the docs don't promise any particular order, so if you want one, you'll
have to make sure of it somehow yourself. Or just live with what you get :)
Just some arbitrary comments below:
Clipboard.SetData(DataFormats.Text, sb.ToString());
// Initializes the variables to pass to the MessageBox.Show method.
string message = counter + " rows copied to clipboard.\nWould you like to
open Notepad\nin order to paste these items?";
I hope you don't deliver this code to a user, do you? You'd drive me wild
with this.... I never use notepad, but I use the clipboard all the time.
string caption = "Clipboard";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
MessageBoxIcon icons = MessageBoxIcon.Information;
// Displays the MessageBox.
DialogResult OpenNotePad;
OpenNotePad = MessageBox.Show(this, message, caption, buttons, icons);
if (OpenNotePad == DialogResult.Yes)
This would drive me wild as a programmer instead of a user :-) Talk about
verbosity! What's wrong with this line:
if (MessageBox.Show(this,
"Do you want ...", "Clipboard", MessageBoxButtons.YesNo,
MessageBoxIcon.Information) == DialogResult.Yes) {
...
Also, MessageBoxIcon.Information doesn't seem to apply here.
Sorry for jumping all over your code :-)
Oliver Sturm
--
http://www.sturmnet.org/blog - MVP C#