behati — 2012-05-09T03:45:10-04:00 — #1
I'm working on a project writing an OPC client (a standard in process engineering) and I've come across a little datadesign issue that I could really use your opinions on! Basically the way the OPC server works is you query using a Synchronous read method and essentially after some back of fourth it returns a lot of values in a single messy System.Array, the nature of the client means that this array can be anything from 6 objects to over a thousand or more.
Luckily, as that has to be done is display this allready optimized data in a GridView, but this is where I'm not sure what the best way to do it is. The amount of columns is not dynamic, so that helps a lot but basically I need it to iterate through the Array, insert it into the Grid creating a new row after each 6 values.
My first approach was to write a method that splits the initial Array into a lot of small arrays but surely there's an easier way? I've also been looking into the BindingList object, it seems like something worth using? or maybe a double for-loop?
So in short, I have a dynamic array of values and for each 6 values I need to insert them into a row in a DataTable/GridView - so row1: v1, v2, v3, v4, v5, v6 /new row v7, v8, v9, v10, v11, v12 and so on unto the breach.
Any ideas would be greatly appreciated!
Thanks in advance <3
wwb_99 — 2012-05-09T15:48:50-04:00 — #2
Key question is "is this an array of objects or a multi-dimensional array?"
If it is the former, it is easy -- just set the datasource property and call DataBind() and you are set, just like binding to any other collection of objects.
Multi-dimensional is a better question -- I'd be inclined to write a wrapper that pushes the multi-dimensional array into a layout object and then bind to the object. Also opens the door for stuff like creating formatting without gads of ASPX template code.
behati — 2012-05-10T21:12:31-04:00 — #3
I ended up cutting the massive Array into small arrays of a set length, and then adding the small array into the DataTable using the .loadDataRow(object, boolean) method.
If anyone should ever need it, here's my final code (C#):
// Cut the values array after each row length and generate a row in the grid
var fifties = from index in Enumerable.Range(0, lol.Length)
group lol[index] by index / 7;
int numRows = 1;
foreach (var fifty in fifties)
if (numRows <= CVcount)
// refresh the Grids
wwb_99 — 2012-05-11T11:54:50-04:00 — #4
You really don't need the datatable there . . .
behati — 2012-05-12T08:42:52-04:00 — #5
How so? I tried binding the Grids directly to the array(s) but I get an Object not compatable error?
wwb_99 — 2012-05-15T15:49:12-04:00 — #6
Interesting -- where did you get that exception? You can definitely databind to anything that implements IEnumerable (and a few other interfaces) so System.Array should work . . .
behati — 2012-05-17T03:07:12-04:00 — #7
I'll try to replicate the error again, since I'm still using my Datatable code.
mittineague — 2014-09-17T23:03:50-04:00 — #8
This topic is now archived. It is frozen and cannot be changed in any way.