1

I have a WindowsForms application that I am compiling as a DLL to be used by another program. This program supplies the DLL with an array filled with information(floats). What I want to do is display these numbers in an organized way(row and columns). The methods I've investigated so far incorporate the use of a DataGridView object, however I do not have a "database", I only have the raw data stored as an array.

Would the only way to do this involve creating a SQL database with my data from the array? Or is there an easier/faster way of doing this?

1
  • Look at the DataGridView's "data binding" support. You can bind to more than DBs. Commented Jun 16, 2016 at 17:00

2 Answers 2

1

Thanks for the replies, but I just ended up looping through the creation of the rows and columns and filling them with my required data.

Creating/initializing DataGridView:

private System.Windows.Forms.DataGridView dataGridView1;
this.dataGridView1 = new System.Windows.Forms.DataGridView();

//Size and location can be changed to whatever you want
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(12, 436);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 70; //Adjusts row header to fit entire "Score" string
this.dataGridView1.Size = new System.Drawing.Size(976, 398);
this.dataGridView1.TabIndex = 10;

Creating rows/columns and filling them with my data:

for (int i = 0; i <= 40; i++)
{
    dataGridView1.Columns.Add("column" + i.ToString(), i.ToString());
    dataGridView1.Columns[i].Width = 22;
}

DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();        

for (int i = 0; i <= 40; i++)
{
    row.Cells[i].Value = scores[0,i]; // "scores" is an Int32[,] array filled with my data
}


dataGridView1.Rows.Add(row);
dataGridView1.Rows[0].HeaderCell.Value = "Score";

The result looked something like this.

Sign up to request clarification or add additional context in comments.

Comments

0

You can send the gridview data in XML format

private void Form1_Load(object sender, EventArgs e) {
    DataSet ds = new DataSet();
    ds.ReadXml(@"XMLFile1.xml");
    gridControl1.DataSource = ds.Tables[1];
    gridView1.PopulateColumns();
}

1 Comment

Just FYI, if you indent each line with 4 spaces, you get "block" code formatting. Then you don't need the backticks (those are only for "inline" code formatting). I fixed your answer here as an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.