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

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

  • On-demand Event Event Date: September 10, 2014 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 how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds