Use MS FlexGrid Control to display multidimensional Datasets

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.