D
Doug
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.SelectedRows.Count.ToString();
foreach (DataGridViewRow row in dgMainView.SelectedRows)
{
sb.AppendFormat("{0} ", row.Cells[3].Value);
sb.AppendFormat(" /* {0} - Wave {1} */", row.Cells[1].Value,
row.Cells[2].Value);
sb.Append(Environment.NewLine);
}
if (counter != "0")
{
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?";
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)
{
string file = Path.GetTempFileName();
StreamWriter sw = new StreamWriter(file);
sw.Write(sb.ToString());
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
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.SelectedRows.Count.ToString();
foreach (DataGridViewRow row in dgMainView.SelectedRows)
{
sb.AppendFormat("{0} ", row.Cells[3].Value);
sb.AppendFormat(" /* {0} - Wave {1} */", row.Cells[1].Value,
row.Cells[2].Value);
sb.Append(Environment.NewLine);
}
if (counter != "0")
{
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?";
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)
{
string file = Path.GetTempFileName();
StreamWriter sw = new StreamWriter(file);
sw.Write(sb.ToString());
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