Click here to Skip to main content
15,943,089 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all!

I have a couple of rather large two-dimensional arrays with data of different datatypes, and I need to display their values to the user. What are my best options on doing this? My first attempt was using the DataGrid, however binding using ItemsSource did not work well with arrays. Apparently the DataGrid will only display the property values of the object it is bound to, and the values in an array are not kept as properties.
Moving the arrays into a datatable and binding it to the datagrid works, however with my amount of data the application lags for seconds when adding the data to the datatable. Also, it seems like a roundabout way of doing things.

What is your take on this, how would you solve such a problem? Are there any other controls which would be more suitable for such tasks? I do not require any functionality beyond displaying the values and scrolling through them.
Posted
Comments
Toli Cuturicu 8-Oct-10 15:16pm    
Very good question.

Can't you create a n object that has two properties, and then a list of those objects, and pump the list full with the array?

C#
/////////////////////////////////////
public class MyItem
{
   public string Property1 { get; set; }
   public int Property2 { get; set; }
} 
<br />
/////////////////////////////////////
public class MyItemCollection : List<myitem>
{
    public MyItemCollection(Array myArray)
    {
        for (int i =0; i < myArray.Length; i++)
        {
            Add(new MyItem(){Property1 = myArray[i][0],
                             Property1 = myArray[i][1]});
        }
    }
}

...
MyItemCollection coll = new MyItemCollection(myArray);
...</myitem>


I honestly don't know if it's going to be any faster than what you've already done, but it's something to try...
 
Share this answer
 
Have you considered embedding Excel in your application and letting it present your data? Excel is, after all, designed for large 2d arrays of data.
 
Share this answer
 
Comments
Fossie1973 8-Oct-10 3:08am    
Well, I did try that on another project a long time ago, and found it to be quite the can of worms. The reason being that Excel automatically interprets the data you send and sets the datatype and format as it sees fit. This is especially a problem if you need to return values from Excel (which I currently don't).

Also, Excel has an upper limit on how many rows/columns it can handle, and I may need to go beyond those limits.
Chris Trelawny-Ross 8-Oct-10 10:29am    
With that much data, I wonder if any out-of-the-box grid(-like) control will give you the performance you need. I would consider creating a "full" custom control - i.e. where you implement OnPaint to render the visible content. Since you're rendering from a uniform XY grid you can filter the data to be drawn based upon the scroll position (and cell size) - so you'll not be attempting to render the whole grid on every adjustment of the scroll bar.
ReportViewer has this build-in functionality. Add a report to your application add a grid there!
 
Share this answer
 
Thank you for your answer John, it was in the lines of what I have been seeing around on the net. What makes it problematic is that I do not know in advance how many columns the array will have, so I do not know the number of properties to give the MyItem class.

However, I just discovered the System.ComponentModel.PropertyDescriptor class, which enables one to define properties programmatically. An example of it's use can be found at www.codeproject.com/KB/database/BindArrayGrid.aspx - Hopefully I will be able to make the adjustments I need to handle input from multiple arrays.

Cheers

Oh, and initial testing showed that the responsiveness from the DataGrid was much, much better using the custom class holdning the array data than binding with a datatable.
 
Share this answer
 
v2
Comments
Toli Cuturicu 8-Oct-10 15:15pm    
Don't add fake answers! You don't fool anybody!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900