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

  • Available On-Demand Today's changing workforce dynamics, economic challenges, and technological advances are placing immense pressure on business leaders to turn their focus on people – their most valuable asset – in order to remain competitive. Research shows that a significant number of new employees quit within one year of taking a new job*. Whether it's through a merger and acquisition, or standard hiring process, like any first impression, early experiences shape their opinions of their new …

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds