reverse order in string writer

D

Doug

Hi

I have a datagrid view that I have enabled a use to copy data from. However
the copy seems to work in reverse.

This results in the last value selected being the first copied to the
clipboard, but I require the data copied to be in the order in the
datagridview.

Is this something I should attend to within the string writer or is there a
simple thing that I am missing here??




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();



thanks



Doug
 
C

chanmm

It seems to me you AppendFormat [3] first befor [1] and [2].Does that method
to you? I don't know what happen to your [0] anyway.

chanmm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top