메뉴 닫기

Using the Flexgrid in VC++


When I had to use the flexgrid for the first time, I was too frustrated to find out that no proper documentation existed on the net. The ones available were too complicated for me to understand. And the ones that were easy were in VB. This article is to help persons who are going to use the flexgrid in their applications using VC++. Also take a look at the Warning note at the end of this article.


Step 1

First, include the msflexgrid control in the project. To do that :-

  1. In the VC++ IDE Menu, go to Project->Add To Project->Components and Controls menu.
  2. Then , in the dialog box that appears, select Registered ActiveX Controls. There, You can see a control named “Microsoft Hierarchical FlexGrid Control…”.
  3. Select that and add it to your project using the Insert button. You can now see the FlexGrid control in the resource editor’s CONTROLS toolbar.
  4. Add it to your dialog as you add a control usually.
Step 2

Then, set the properties as you want it to be. Right click on the grid and select the Properties option. Change the settings there as per your requirements.

Step 3

Add a member variable for that grid. E.g. m_Grid. The sample given below is for an example. Use it as a guideline to make your application.

Step 4

Its better to clear the flexgrid before you do any operations on it. To do that, use :-

Hide Copy Code

Step 5

To add records to the Grid, use something like this.

Hide Copy Code

CString strName,strRemarks;
m_nCount = 0;
// Clear and refresh the grid
// Get the value for strName from the database here
// Get the strRemarks from the database here
m_nCols = m_Grid.GetCols();
m_Grid.SetTextArray(0, "Name " );      // First  Column
m_Grid.SetTextArray(1, "Remarks " );   // Second  Column
// Fill First Column
m_Grid.SetTextArray(  m_nCols * m_nCount + 0,strName );
// Fill Second  Column
m_Grid.SetTextArray(  m_nCols * m_nCount + 1, strRemarks );
// Redraw the grid
Step 6

To retrieve data from the Grid when the user double clicks on a record, add a double click message handler for the grid using the class wizard. Assuming that you have named the function as OnDblClickGrid, then :-

Hide Copy Code

void YourDialog::OnDblClickGrid()
    // Get the current row and column
    int nRow = m_Grid.GetRow();
    int nCol = m_Grid.GetCol();
    CString strName,strRemarks;
    // Get data from the First Column
    strName    =  m_Grid.GetTextMatrix(nRow,nCol+0);
    // Get data from the Second Column
    strRemarks =  m_Grid.GetTextMatrix(nRow,nCol+1);
Step 7

To move to the previous record, do this :-

Hide Shrink Copy Code

void YourDialog::OnBtnPrevious()
    // Get the current selection
    int NextRow = m_Grid.GetRowSel();
    // If the position is at the last record, return
    if(NextRow <= 1)
        long BackColor[2],FontColor[2];
        int Column;
        // The BackColor and the FontColor variables
        // are manipulated because we want a
        // selected effect to be given to the previous
        // record. Here, we are merely changing
        // the color of the selected
        // row to give it that effect.
        BackColor[0] = 0x00FFFFFF;
        BackColor[1] = 0x00FFFFB0;
        FontColor[0] = 0x00400000;
        FontColor[1] = 0x000000FF;
        for(Column = 1; Column < m_Grid.GetCols(); Column++)
        for(Column = 1; Column < m_Grid.GetCols(); Column++)
Step 8

To got to the Next record, do the reverse of the code above. Instead of m_Grid.SetRow(--NextRow) it would be m_Grid.SetRow(++NextRow).


Whenever you use a flexgrid in your application, you have to be twice as careful. Be sure to take regular backups. Sometimes, you might note that your compilation time is too longer than usual. It would be more and more slow with each build. If you feel so, check the size of your .rc file. If its size is abnormal ( I cant specify a size because it depends on your project and its resource contents ),then delete the flexgrid from your application , Close Visual Studio and copy the .rc file from your backup. Open your project again. That should solve your problem. I’m not sure why this happens, maybe its a bug in flexgrid that corrupts or damages it. But from your side, be careful.


The flexgrid is a very easy control to use. But whenever you use it , repeat the mantra “take backups of your .rc file regularly” until it becomes a habit. That’s it. All luck and have a great time.


  1. tinyurl.com

    The other day, while I was at work, my sister stole my iPad and tested to see if it can survive a thirty foot drop,
    just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.

    I know this is totally off topic but I had to share it with someone!

  2. Jenifer Hopkinson

    I just want to say I’m newbie to blogs and seriously loved you’re web-site. Very likely I’m want to bookmark your website . You amazingly have very good stories. Appreciate it for sharing with us your blog.

  3. buy viagra online germany

    I?m amazed, I have to claim. Truly rarely do I run into a blog site that?s both educative and also entertaining, and let me inform you, you have actually hit the nail on the head. Your suggestion is exceptional; the concern is something that insufficient individuals are talking intelligently about. I am really pleased that I stumbled across this in my look for something associating with this.

  4. security screen mesh

    Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your site? My blog is in the exact same niche as yours and my visitors would really benefit from some of the information you provide here. Please let me know if this alright with you. Regards!

  5. John Deere Service Manuals

    You really make it show up really easy using your presentation however i locate this kind of issue being really something which I believe I might in no way realize. It appears as well intricate and extremely great personally. My partner and i’m taking a look in advance on your subsequent submit, We?|ll attempt to get the hang on to than it!

  6. cbd dog biscuit recipes

    There are some intriguing points in time in this article yet I don?t recognize if I see every one of them center to heart. There is some credibility however I will certainly hold viewpoint up until I look into it additionally. Great post, thanks as well as we want much more! Contributed to FeedBurner also

  7. cbd oil benefits speech

    After study a few of the post on your internet site now, as well as I truly like your way of blogging. I bookmarked it to my bookmark website checklist as well as will be examining back quickly. Pls have a look at my website too and also let me understand what you believe.

  8. my company

    There are some intriguing points in time in this short article yet I don?t recognize if I see every one of them center to heart. There is some validity yet I will certainly take hold opinion till I check into it even more. Great article, many thanks and we want more! Added to FeedBurner as well

  9. Mickey Golabek

    An intriguing conversation is worth comment. I believe that you need to create a lot more on this topic, it could not be a forbidden topic however typically individuals are inadequate to speak on such topics. To the following. Thanks

  10. visit here

    Can I simply say what a relief to find somebody that really knows what theyre discussing on the web. You certainly know just how to bring a problem to light and make it important. More individuals need to read this and recognize this side of the story. I cant think youre not a lot more popular due to the fact that you most definitely have the gift.

  11. like it

    When I initially commented I clicked the -Notify me when new comments are included- checkbox and currently each time a comment is added I obtain four emails with the very same comment. Exists any way you can eliminate me from that solution? Many thanks!

  12. more tips here

    Youre so great! I don’t mean Ive check out anything such as this prior to. So good to find somebody with some original ideas on this subject. realy thanks for beginning this up. this web site is something that is needed on the web, someone with a little originality. helpful task for bringing something new to the internet!

  13. address

    There are some intriguing points in this short article however I don?t understand if I see every one of them center to heart. There is some validity but I will take hold point of view up until I explore it further. Great article, many thanks and we want extra! Added to FeedBurner too

  14. check my site

    Youre so great! I do not mean Ive check out anything like this prior to. So good to locate someone with some original ideas on this subject. realy thanks for beginning this up. this website is something that is required on the web, someone with a little originality. helpful job for bringing something brand-new to the web!

  15. Sylvia

    This is very attention-grabbing, You are an excessively skilled blogger. I’ve joined your rss feed and sit up for looking for extra of your magnificent post. Also, I’ve shared your website in my social networks

댓글 남기기

이메일은 공개되지 않습니다.