ATL Tree Control and OLE DB

This small example is for the beginner who wants to create an ActiveX control by superclassing the windows common control using ATL 3.0. If you don't have VC6, you need to install OLE DB1.1 from VC5 for this project to work properly.

On this site, a lot of excellent examples about tree controls are already there so why this example? Because:

  1. My tree control create by using ATL instead of MFC
  2. Using OLD DB to save tree structure and load it back
  3. Right click to open popup menu and more...
The main reason I want to post my article is because I am using OLE DB and OLE DB is still new to some programmers, especially for a new beginner.

Before you use this article, you should have Access database to see OLE DB in action. If you don't have Access database but you have another database like Oracle, SQLServer or SQL Anywhere and you want to know how to do it is beyond the scope of this article.

Open Access database and create a table, and name it any name as you like. Create four fields in the table with the names as follow:

  • ITEM_NODE ( int )

  • ITEM_NAME ( text )

  • INDENT_LEVEL ( int )

  • ITEM_DATA ( long ) [ primary key ]

if you want to create some bogus data, go head and do it, otherwise the example will create default data for you. If you don't want to use any database at all, two things you need to do:

  1. Open your project, click on FileView tab, remove the file name: Tree.h
  2. Open MyTreeControl.h, go to the method name " OnDestroy() " and comment out the line: " this->SaveTree(); ", after all select Build on the menu and select Rebuild All.

When the project is running, the first thing you need to do is select " Microsoft Jet 3.51 OLE DB Provider ( if you have another OLE DB Provider on your system, go head and select it. ", second is select your data source. If you don't have any data in your table yet, just click cancel when the dialog asking you to select a driver and you will have the default data which I created for you.

To test this control, You can select the ActiveX Control test container to test it or you can create a new MFC project with Dialog base. When the project is completely constructed, click on Resource View, open Dialog resource, right click on dialog and select insert ActiveX control..., that is all you need to do. If you have any question about this project or you do not understand some line of codes, please post your comment and I will try to answer as soon as possible but within my knowledge, because I just have 2 year experience on Visual C. I hope you can understand my example and can apply part of it in your project in the future.

Download demo project - 198 KB



Comments

  • Thanks for the interesting

    Posted by Jessica on 01/12/2015 10:41am

    Thanks for the interesting article.

    Reply
  • Thanks for the interesting

    Posted by Benjamin S Ayoub on 01/11/2015 05:03pm

    Thanks for the interesting article.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Organizations are increasingly gravitating toward mobile-first application development as they assess the need to revamp their application portfolios to support touch computing and mobility. Consumerization has brought higher expectations for application usability along with the mobile devices themselves. Enterprises are increasingly shifting their new application acquisitions and development efforts toward mobile platforms. With this backdrop, it is natural to expect application platform vendors to invest in …

  • Cloud computing isn't new, but it's still a hot topic in technology circles. Moving to the cloud has done great things for many businesses. When it comes to handling a basic business necessity, cloud computing has brought many improvements to overall business continuity. Using the cloud for DR makes a lot of sense for many, but it's not exactly the most simple concept. Read this eBook to find answers to all the key questions IT professionals have about cloud-based disaster recovery, and helpful info around the …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date