开发者

How to use multiple List<> as DatagridView's datasource

I'm looking for a highly efficient way to save data to a table like structure in C#. The number of rows, columns and data type for each column is determined at runtime. One of my approaches is to create a struct that defines a column. The struct consists of ColumnName, Units, and a generic List of doubles. (For now I am sticking to one data type). I then instantiate a struct for each column and fill its list. This method works pretty well and is much cleaner than some other methods we've tried, I am able to save 100,000 rows of 3 columns in about 12 milliseconds. The problem I am having is displaying the data. I am able to display my "table" in a datagridview by looping through my columns and rows and filling the DGV cell by cell, but this is, not suprisingly, very slow. Is there a way to use my 3 lists as a datasource for the DGV? Can each column have it's own datasource? Is the an alternative开发者_开发百科 to the DataGridView that I should try?


What are the "3 lists" here? I can see the list of doubles... if the columes are dynamic, then implementing ITypedList might be useful, but I'll be honest - it is a pig to implement correctly; it would be easier to fill a DataTable. I've used this, for example, to transpose an array on the fly.

If performance is your concern, perhaps switch to virtual mode? This would appear to match your use-case quite well.


Have you tried filling a DataTable first and then binding that DataTable to the DataGridView?

If it's a WebApplication you can do a foreach statement and build a table from code-behind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜