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

  • On-demand Event Event Date: May 18, 2015 While the idea of using facial and/or gesture recognition to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development efforts. There are many different ways in which Intel and Unity Technologies have been working together to help speed the development of games with the Intel&reag; RealSense™ SDK (software developer kit). Check out this webcast to join a panel of experts as they …

  • On-Demand eSeminar DevOps and Cloud are all the rage in IT, but the two terms relating process and computing aren't mutually exclusive. Join us to see how your movement into cloud changes the way you develop, deploy, test and manage, and how DevOps can actually be a good thing when coupled with cloud.

Most Popular Programming Stories

More for Developers

RSS Feeds

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