manually creating columns in a datagrid

Jan 5, 2010 at 4:50 PM
Edited Jan 5, 2010 at 4:54 PM


at first, please excuse my english, it's not my native langue :-)

i'm facing some problems using the virtual datagrid control. i have a large table with integers in each cell which determine some kind of "field type". when i try do display them in a datagrid control, it works fine as long as i'm just binding the table to the datasource. but when i try to create the columns myself, like this:


for (int i = 0; i < SIZE; i++)
    mapDataGrid.Columns.Add(i.ToString(), i.ToString(), new SourceGrid.Cells.Virtual.CellVirtual());


it only shows empty cells and no column headers. using "typeof(string)" instead of "new SourceGrid.Cells.Virtual.CellVirtual()" gives each cell fillded with

"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt" which (following to google) is equivalent to "Object reference not set to an instance to an object".

the idea behind creating the columns myself is, to later set them to an image type and to replace the type-integer with an associated image. (i tried to fill the underlaying DataTable directly with the images too, which works with a datagridview but shows nothing with sourcegrid)

so how do i have to create the columns? the examples unfortunately didn't help. and is there a more obvious way to replace the integer with the image then changing the GetCell method (or so) which returns the values for each cell?



Jan 6, 2010 at 10:53 AM

An alternative solution  may be resolve your problem , datagrid  designed to be bouded to a source of data  , so why not you create your own datatble  and fill it manually withe your numbers data then affect the datasource of the datagrid to this datatable  :)

Jan 6, 2010 at 1:58 PM

thanks for your reply.

in fact, i think, thats what i'm doing. i create a datatable with my values which then is passed via

mapView = mapTable.DefaultView;
mapDataGrid.DataSource = new DevAge.ComponentModel.BoundDataView(mapView);

to the datagrid.

filling the DataTable mapTable with images now  only shows "System.Drawing.Bitmap" in each cell. so i tried to set the column type to

for (int i = 0; i < SIZE; i++)
    mapDataGrid.Columns.Add(i.ToString(), i.ToString(), new SourceGrid.Cells.Virtual.Image());
which gives me only empty cells. so how do i display the images correctly in the virutal cell?

Jan 6, 2010 at 8:08 PM

just to finish this: i finally found out that i went through the examples too quickly and could solve my problem using the BoundImage model (ex. 41). even though i think it is a bit complicated to access the datasource via the PropertyDescriptor.