How to bind Special datasource to WPF DataGrid?

Dec 24, 2008 at 9:53 AM

Hi, everyone,

My datasource is a little special, neither the DataTable from database, nor an ObservableCollection
(e.g. the famous DataGrid sample from vinsibal), it is a Table class written by others, which only provides
following infomations: rows count, columns count, each column's name, a method getCellData(int row, int column)
to get the specified cell's data through the row and column index.

For demo, I pack the datasource to a DataTable by getting each cell's data then filling it to the DataTable, then
bind the DataTable to DataGrid's ItemSource, you can see the performance is terrible, e.g. we have 1000 rows
and 10 columns, so there is a 1000*10 loop exists, so the 1st question is that is there a guide to pack this kind of
datasource, so that I can bind it to DataGrid's ItemSource?

Also, because I don't know any more details about the Table and I want to use DataGridTemplateColumn for some
column(e.g. the DataTime column, with a TextBlock and a DatePicker), so I should set AutoGenerateColumns to true,
then in the DataGrid's AutoGeneratingColumn event, I intend to customize each column(e.g. set binding, special editing
template, etc.) according to each column's type, is that possible? any suggestions?

Thanks a lot,