Multicolumn Combobox

If you ever want to put an item into a ComboBox and separate the subitem into a column-wise fashion, maybe this CJCombo is a good candidate to serve your needs. I combined my code with Zafir's CTooltip code, and the derivation of this product is a Multicolumn Combobox.

The pictures that I included in this page should give you a pretty good idea what JCombo is about.

All you have to do is:

  1. Put an Ownerdraw Combobox on your form.
  2. Declare the Combobox as JCombo.
  3. Use CJCombo::AddItem(text,Column,Row) instead of AddString(..) to add an item into a list.
  4. If you need to get a content from a list, use CJCombo::GetLBText(Column,Row,&rString);

Example: To use my Multicolumn Combobox:

m_MULTICOLUMNCOMBOBOX.FormatList(1,DT_LEFT,FALSE,NORMAL);
// one column setting, no grid lines, show titletip
CString str;
for (i=0;i<=10;i++){
  str.Format("Item %d",i);
  m_MULTICOLUMNCOMBOBOX.AddItem(str,0,i);
  .
  .
}

OR multicolumn:

// three columns setting
m_MULTICOLUMNCOMBOBOX.FormatList(3,DT_LEFT,FALSE,EDGE);

for (i=0;i<=20;i++){
  str.Format("Item : %d",i);
  m_MULTICOLUMNCOMBOBOX.AddItem("TESTING",0,i);
  m_MULTICOLUMNCOMBOBOX.AddItem(str,1,i);
  m_MULTICOLUMNCOMBOBOX.AddItem(_T("3rd Column0123456789"),2,i);
  .
  .

If you find any bugs, or run into a deep deep problem, or could not get it to work with my JCombo, please e-mail me at jakawan@yahoo.com. Other than that, have fun!!!

This article is an ideal for someone who wants to learn about Ownerdraw, MFC Collection class (e.g. CPtrList ), and ToolTip. It also is practical for database usage. For example, if you have a table with some unique primary key, you can hide the index key and only display the content of that record. The Dropdown window is the original window from MFC where it was custom painted as an Ownerdrawn window. The nice thing about this is that the CJCombobox does not "sub class" from another control, so performance should be great because it will cause fewer clock cycles to initialise the control.

Bug Fixes

  1. Allow multiple columns, and only display one column (like Access, hiding a primary index key).
  2. Allow interative search for selected column or all columns and rows.

Known Bugs

  1. Tiltle tip window does not get painted properly the first time it's being displayed. Or, when you have a Dropdown Combobox, the Tooltip will not display the text.
  2. The Tooltip will move along with the Scrollbar as long as you keep pressing the buttons.

Please always e-mail me for upgrades, questions, bugs found, and so forth. If you like my CJCombobox, please add a little comment on this page. Thanks.

Downloads

Download zipped source files.
Download zipped project files (Most recent files)
Download sample file - 2.27 Mb (Newly added file)

Date Last Updated: July 18, 2003


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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds