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

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds