Payoff data table

I want to copy two columns from excel and work on them in a C # program. What's the best component to use to simulate an excel column in a payoff form?

+2


a source to share


2 answers


You can write a routine that pulls the clipboard data with something like:

    private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // create dataset to hold csv data:
        DataSet ds = new DataSet();
        ds.Tables.Add();
        ds.Tables[0].Columns.Add();
        ds.Tables[0].Columns.Add();
        ds.Tables[0].Columns.Add();
        ds.Tables[0].Columns.Add();
        ds.Tables[0].Columns.Add();
        ds.Tables[0].Columns.Add();

        string[] row = new string[1];

        // read csv data from clipboard
        IDataObject t = Clipboard.GetDataObject();
        System.IO.StreamReader sr =
                new System.IO.StreamReader((System.IO.MemoryStream)t.GetData("csv"));

        // assign csv data to dataset      
        while (!(sr.Peek() == -1))
        {
            row[0] = sr.ReadLine();
            ds.Tables[0].Rows.Add(row);
        }

        // set data source
        dataGridView1.DataSource = ds.Tables[0];
    }

      



Cleaned up code and tested sample code. It is still crude, but it demonstrates the possibility with a fixed number of columns. (Pasting in more than six cases will fail, will still work.)

+3


a source


You can use DataGridView control .



+4


a source







All Articles