-
Mar 6th, 2014, 02:55 AM
#1
Thread Starter
Junior Member
[RESOLVED] Add two arrays to datagrid view
I have two arrays xdat and ydat and I want to display them into datagridview.
I tried to use
Code:
DataGridView1.Rows.Add(jdxDat, jdyDat)
but I got the error "No row can be added to a Data grid view control that doesn't have columns. Columns must be added first".
Can you suggest how to add rows ?
For example my jdxData looks like
Code:
jdxDat = {0,1,2,3,4,5}
and
Code:
jdyDat = {5,10, 11,19, 18,21}
Thanks for any help.
-
Mar 6th, 2014, 02:58 AM
#2
Re: Add two arrays to datagrid view
Did you even read that error message? It tells you exactly what to do.
Columns must be added first
what part of that is unclear?
Also, you can't add the whole array to one row. You need to use a loop and add one element from each array to each row.
-
Mar 6th, 2014, 03:05 AM
#3
Thread Starter
Junior Member
Re: Add two arrays to datagrid view
Thanks. I figured it out.
Code:
DataGridView1.ColumnCount = 2
For i = 0 To jdxDat.Length - 1
DataGridView1.Rows.Add(jdxDat(i), jdyDat(i))
Next
How do I add header to this datagridview ? For example on column1 I want to write "distance", and column2 I want to write "value".
Thanks.
-
Mar 6th, 2014, 03:07 AM
#4
Re: Add two arrays to datagrid view
You should be adding the columns in the designer, where you can set the header text and more besides.
-
Mar 6th, 2014, 03:12 AM
#5
Thread Starter
Junior Member
Re: Add two arrays to datagrid view
Thanks so much for your time and help. I was able to figure that out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|