1. Add the FlexGrid Control.
Right-click the toolbox in VS 2005, and select choose items from the shortcut menu.
In the displayed choose toolbox items dialog box, select the COM components tab and select Microsoft flex Grid Control version 6.0 in the list box]
Click OK. The Microsoft FlexGrid Control is added to the toolbox.
2. Use msflexgrid to display multidimensional data sets
Private void displaycellset (cellset CS)
{
Cellsetgrid. redraw = false;
Try
{
Cellsetgrid. Clear ();
Axiscollection axes = cs. axes; // gets the set of axes.
Int axescount = axes. count;
If (axescount> 2)
Throw new exception ("this sample application do not support ");
Set columns = NULL;
Set rows = NULL;
Int columncount = 0;
Int rowcount = 1;
Int fixedcolumncount = 0;
Int fixedrowcount = 0;
int gridrow = 0;
int gridcolumn = 0;
If (axescount> 0)
{< br> Columns = axes [0]. set;
columncount = columns. tuples. count;
fixedrowcount + = columns. hierarchies. count; // number of fixed Rows
}
If (axescount> 1)
{< br> rows = axes [1]. set;
rowcount = rows. tuples. count;
fixedcolumncount + = rows. hierarchies. count; // number of fixed columns
}
Cellsetgrid. Cols = fixedcolumncount + columncount; // you can specify the number of columns in the control.
Cellsetgrid. fixedcols = fixedcolumncount; // set the fixed number of columns of the control.
Cellsetgrid. rows = fixedrowcount + rowcount; // you can specify the number of rows in the control.
Cellsetgrid. fixedrows = fixedrowcount; // set the variable
Gridcolumn = fixedcolumncount;
// Add a column title
Foreach (tuple in columns. tuples)
{
Gridrow = 0;
Foreach (Member member in tuple. Members)
{
Cellsetgrid. set_textmatrix (gridrow, gridcolumn, member. Caption );
Gridrow ++;
// Cellsetgrid. set_colwidth (1, 2000 );
}
Gridcolumn ++;
}
// Add a row title
If (rows! = NULL)
{
Gridrow = fixedrowcount;
Foreach (tuple in rows. tuples)
{
Gridcolumn = 0;
Foreach (Member member in tuple. Members)
{
Cellsetgrid. set_textmatrix (gridrow, gridcolumn, member. Caption );
Gridcolumn ++;
}
Gridrow ++;
}
}
// Fill in data
Int icell = 0;
For (gridrow = fixedrowcount; gridrow <cellsetgrid. Rows; gridrow ++)
{
For (gridcolumn = fixedcolumncount; gridcolumn <cellsetgrid. Cols; gridcolumn ++)
{
If (CS. cells [icell]. value! = NULL)
{
Cellsetgrid. set_textmatrix (gridrow, gridcolumn, CS. cells [icell]. value. tostring ());
}
Icell ++;
}
}
// Set the column width
Int maxwidth = 0;
For (gridcolumn = 0; gridcolumn <cellsetgrid. Cols; gridcolumn ++)
{
For (gridrow = 0; gridrow <cellsetgrid. Rows; gridrow ++)
{
Int actualwidth = cellsetgrid. get_textmatrix (gridrow, gridcolumn). length * 100;
If (actualwidth> maxwidth)
Maxwidth = actualwidth;
}
Cellsetgrid. set_colwidth (gridcolumn, maxwidth );
}
}
Catch (exception ERR)
{
MessageBox. Show (ERR. Message );
}
Finally
{
Cellsetgrid. redraw = true;
}
}
Program Shows the execution result:
File Download path:
Http://files.cnblogs.com/sorosjing/CellGridDemo.rar