VC cvsflexgrid basic usage

Source: Internet
Author: User
VC msflexgrid basic use
   

1. Bind The member variable m_flexgrid to the FlexGrid Control.

2. Set the number of rows and columnsM_flexgrid.setcols (4); // you can specify the number of columns m_flexgrid.setrows (6). // you can specify the number of rows.

3. Set a fixed number of rows and a fixed number of ColumnsM_flexgrid.setfixedrows (1); // you can specify a fixed number of rows as one.

M_flexgrid.setfixedcols (0); // you can specify 0 columns as fixed columns.

4. Set the column width and Row Height.M_flexgrid.setcolwidth (1500); // you can specify for a column with column number 1.

M_flexgrid.setrowheight (2,300); // set the Row Height of Row 2 to 300

5. set text alignmentM_flexgrid.setcolalignment (); // you can specify the text alignment of column 1.

The parameter description is as follows: the top of the 0 unit content is left aligned. The center of Unit 1 content is left aligned. The default value of the string. The bottom of Unit 2 content is left aligned. Center the top of Unit 3 content. Center the content of Unit 4. Center the bottom of Unit 5. The top right of Unit 6 content is aligned. The center and right alignment of Unit 7 content. The default value of a number. The bottom of the 8-unit content is right aligned. The 9-unit content is normally aligned. Align left in the middle of the string and right in the middle of the value.

6. Set the header and cell contentM_flexgrid.settextarray (0, "head1"); // you can specify head1 as the header (column 1st"

M_flexgrid.settextmatrix (, "text"); // set the cell (Row 1 column 1) to "text"

7. Add a rowM_flexgrid.additem ("addstring", (colevariant) (3l); // Add a row at position 3.

8. Merge CellsFor (I = 0; I <4; I ++)

M_flexgrid.settextmatrix (5, I, "Total"); // set the content of cells with row number 5 and column number from 0 to 4 to the same "Total"

M_flexgrid.setmergecells (2); // sets the cell merging mode (below)

M_flexgrid.setmergerow (5, true); // you can specify the row to be merged.

The setmergecells function has the following parameter values:

0: the default flexmergenever option is not merged.

1: irregular combination of flexmergefree

2: flexmergerestrictrows row merge

3: flexmergerestrictcolumns column merge

4: flexmergerestrictboth row, columns are merged

Note that only cells with the same content can be merged.

9. Create an editable FlexGrid Control

Place an edit control, bind the member variable to m_edit, and set the initial state to invisible.

Response to the Click Event of the FlexGrid Control:

Void cblackbkdlg: onclickmsflexgrid ()

{

Long LCOL = m_flexgrid.getcolsel (); // obtain the row number

Long lrow = m_flexgrid.getrowsel (); // you can call this operation to obtain the column number.

If (lrow> m_flexgrid.getrows () | lrow = 0) // you can determine whether a click is valid.

Return;

Crect rect;

M_flexgrid.getwindowrect (& rect); // obtain the window rectangle of the FlexGrid Control

Screentoclient (& rect); // convert to a client rectangle

CDC * PDC = getdc (); // The unit of the function length of the msflexgrid control is twips, which must be converted to pixels, 1440 Ti = 1 inch // calculate the conversion ratio of pixel points and Ti

Int ntwipsperdotx = 1440/PDC-> getdevicecaps (logpixelsx );

Int ntwipsperdoty = 1440/PDC-> getdevicecaps (logpixelsy); // calculate the coordinates in the upper left corner of the selected grid (in pixels)

Long y = m_flexgrid.getrowpos (lrow)/ntwipsperdoty;

Long x = m_flexgrid.getcolpos (LCOL)/ntwipsperdotx; // calculate the size of the selected cell (in pixels ). In actual debugging, adding 1 is better.

Long width = m_flexgrid.getcolwidth (LCOL)/ntwipsperdotx + 1;

Long Height = m_flexgrid.getrowheight (lrow)/ntwipsperdoty + 1; // form the area of the selected rectangle

Crect RC (X, Y, x + width, Y + height); // convert it to the coordinates RC in the relative dialog box. offsetrect (rect. left + 1, rect. top + 1 );

Cstring strvalue = m_flexgrid.gettextmatrix (lrow, LCOL); // get the cell content
M_edit.showwindow (sw_show); // display control m_edit.movewindow (RC); // change the size and move it to the position of the selected grid.

M_edit.setwindowtext (strvalue); // display text

M_edit.setfocus (); // obtain the focus}

After the focus is released, write the data back to the cell. Respond to the Edit Control's en_killfocus event:

Void cblackbkdlg: loads () {cstring strinput; getdlgitemtext (idc_edit_change, strinput); // obtain the input box content m_flexgrid.settext (strinput); // set the cell content m_edit.showwindow (sw_hide );

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.