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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds