We help IT Professionals succeed at work.

C# - How Show thet myArray in DataGridView?

ocaccy
ocaccy asked
on
How to show the content of the array on dataGridView?

myArray1[320,4]
dataGridView1

ocaccy
Comment
Watch Question

Commented:
Try this
ArrayList s = new ArrayList();
s.Add("1st Item");
s.Add("2nd Item");
GridView1.DataSource = s.ToArray(typeof(string));
GridView1.DataBind();

or use a for loop the add item to the grid
Kiran SonawaneProject Lead
BRONZE EXPERT
Top Expert 2011
Commented:

Author

Commented:
Hi sonawanekiran

I need to enter data into the correct cells.
Phase 1 - data collection and storage in the arrays.
Phase 2 - will take the minimum and maximum selections string myArrays[320,4] and store in double myArray9[320,18].
Phase 3 - we'll take the average of the Selections of the double myArray9[320,18] and store in double myArray10[32,18].
Phase 4 - will take the minimum and maximum of the selections of the double myArray10[32,18] and store in double myArray11[10,6].
5th stage - we will take the values ¿¿in myArray11[10,6] and launched in ZedGraph with graphic line.
At all stages put the values ¿¿in datagridviews.

So I need to put the data right
Best Regards,
ocaccy
Commented:
Can you please tell us exactly what you're trying to accomplish? What are those random numbers for?
If you're trying to store huge data array into datagrid at any given time, I suggest store in a tree.
Then after finish, convert the tree to datatable and bind to datagrid

Author

Commented:
I'll explain, but first want to say that do not know if arrays[,] is the best choice.
If they have a good tip, I would like to hear.

My project has six devices RS485 connected to the PC by converter RS485/USB.
I get the data in string form
(01,03260,00552,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_01 = new string[240, 4];
(02,03260,00554,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_02 = new string[240, 4];
(03,04253,00552,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_03= new string[240, 4];
(04,03460,00554,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_04 = new string[240, 4];
(05,03260,00556,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_05 = new string[240, 4];
(06,06260,00557,00032, message, message)
I'm currently trying to put a string in to public string[,] a_i_id_06 = new string[240, 4];
devices at intervals of 10 seconds.
I have to put these strings somewhere to work with them in later phases.

I need to display them in datagridview so entering the arrays.

ocaccy
BRONZE EXPERT
Commented:
Hi,
I have an idea for you that first you have to create DataTable by using this 2 dim Array(By using any Loop like foreach etc.). When data table is available then you can assign this dataTable to DataGridView as Datasource.
you can apply different queries for on that DataTable for getting required results as Minimum,Maximum etc.

Regards,
Dani

Author

Commented:
Hi, guys.

Dani, your suggestion seems to me a way.
I'm getting data from the devices: ID01, ID02, ID03, ID04, ID05, ID06 every 10 seconds, but still do not know how to send data to the arrays as they arrive, and how to show these arrays to check they are receiving the data.

It has a model that I can learn?

Regards,
ocaccy
BRONZE EXPERT
Commented:
can you please tell me the format of arrived data.
Dani

Author

Commented:
¿01,00668,00047,00056,message, message

I don´t need this symbol. ¿

ocaccy
BRONZE EXPERT
Commented:
you can add above data string direct into some sort of datatable
by using string.split(',') function
you get every data element then these element can be assigned to datatable or Array it up to you


Dani
You can make use of datatable instead. Datatable will give you more flexibility.
Store your data in datatable instead of 2D array and use it as datasource.

Author

Commented:
I don´t know this.
How do this?

Regards
ocaccy
Since you are using 2D array, you can structure your datatable for 4 column layout. You can add as many rows as you need. Just a sample code, you might be knowing this,
           
 DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));

            dt.Rows.Add(1, "Batman");
            dt.Rows.Add(2, "Spiderman");

            dataGridView1.DataSource = dt;

Open in new window

Author

Commented:
Hi guys.

TJCombos.

How do this with the arrays, for example string[,] a_i_id_01 = new string[240, 4]; ?
string[,] a_i_id_01 = new string[240, 4]; 
//ArrayList s = new ArrayList();
s.Add("1st Item");
s.Add("2nd Item");
GridView1.DataSource = s.ToArray(typeof(string));
GridView1.DataBind();

Open in new window

Author

Commented:
Hi, VijayBalkawade.
I don´t know how to connect the array in datatable in datagridview.
My array is double a_i_sagyou1 [240.18].
Do you have a tip?

ocaccy
DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));

            dt.Rows.Add(1, "Batman");
            dt.Rows.Add(2, "Spiderman");

            dataGridView1.DataSource = dt;

Open in new window

Author

Commented:
Thank you.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.