Solved

OWL TComboBox help

Posted on 1997-04-28
9
298 Views
Last Modified: 2013-12-04
I have a custom dialog box (which I'm loading from a resource) that is created by a function call within a DLL that I'm writing.  I have three combo boxes in the dialog, which I wish to use as dropdown single-selection lists.  I have written my own class which inherits from TDialog.  I overloaded SetupWindow() to initialize the comboboxes to contain the text I want. Here's the current code that I'm trying to make work:

void UserDataDialog::SetupWindow()
{
  // Can't play with controls until TDialog::SetupWindow()
  // is called
  TDialog::SetupWindow();

  gender->InsertString(" ", 0);
  gender->InsertString("Male", 1);
  gender->InsertString("Female", 2);

  ageRange->InsertString(" ", 0);
  ageRange->InsertString("under 21", 1);
  ageRange->InsertString("21 and over", 2);

  incomeRange->InsertString(" ", 0);
  incomeRange->InsertString("Got a tax refund", 1);
  incomeRange->InsertString("Owed more taxes", 2);
}

My problem is that the comboboxes are completely empty if you click on the dropdown arrow with the mouse.  However, I have found that if you use the keyboard to select an item (using the up/down arrow keys), the strings are actually there.  In either case, though, the combobox reports that the selected item is index number zero, regardless of what may have been selected.  The InsertString functions actually succeed (I tested that first thing), but still the dropdown list is not properly initialized.  I tried using SendDlgItemMessage, but that didn't work either.  Using Borland's WinSight tool, I know that the boxes are being created and are receiving mouse clicks.

*** What am I missing? ***

Feel free to email me at olsonmd@aureate.com
0
Comment
Question by:gurumike
  • 5
  • 4
9 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
Comment Utility
Try to use just AddString:gender->AddString(" ");
gender->AddString("Male");
gender->AddString("Female");// Now select "Female" (if your combobox has no CBS_SORT style)gender->SetSelIndex(2);

ageRange->AddString(" ");
ageRange->AddString("under 21");
ageRange->AddString("21 and over");
// Now select "under 21"
ageRange->SetSelIndex(1);

0
 

Author Comment

by:gurumike
Comment Utility
I tried doing as you suggested.  I failed to mention in the question that I had tried AddString() before, and it had failed; however, I previously didn't do any SetSelIndex() calls.  So, I tried it without effect.  I am using BC++ 5.02 - could v5.02 have a bug that causes this to fail?  I checked Borland's website recently and was unable to find any bug reports of this nature.
I think I'll increase the number of points this question is worth - I may have underestimated its trickiness.  I'm not going to reject this answer though until I give you a chance to comment!

0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
Can you post your source code (constructor with calls to TEdit, SetupWindow(), resource statements)?
0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
You can write me directly to nick@rtzi.ru
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:gurumike
Comment Utility
[Sent relevant source to NickRepin]

0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
You have used too small height for your edit controls (12).
Set it as 80 (for example). This value defines not the height of selection field but the height of drop-down list! So your drop-down list window is too small to display items.

Check this in resource editor by selecting Dialog->TestDialog menu.


0
 

Author Comment

by:gurumike
Comment Utility
Great!  Thanks for the answer.  As I received your email, I found that this question had been asked before (and I got the same answer there, too!)  Experts Exchange needs to do some interface work...

The only thing that still bugs me is that my code still reports zero as the index of the selected values, regardless of what I choose.  Any hints there?  (I did put that in the original question, although it's probably a more trivial problem)

0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
You used following code:int UserDataDialog::Execute() {
  int ret = TDialog::Execute();
  data->gender = gender->GetSelIndex();
  data->ageRange = ageRange->GetSelIndex();
  data->incomeRange = incomeRange->GetSelIndex();
  return ret; }
But if TDialog::Execute() executes then all controls of this dialog box does not exist (I mean windows, not TComboBox objects). So their cannot respond to GetSelIndex().Use CleanupWindow() instead of Execute():void UserDataDialog::CleanupWindow(){
  data->gender = gender->GetSelIndex();
  data->ageRange = ageRange->GetSelIndex();
  data->incomeRange = incomeRange->GetSelIndex();
  TDialog::CleanupWindow();}or,bool UserDataDialog::CanClose()
{  data->gender = gender->GetSelIndex();
  data->ageRange = ageRange->GetSelIndex();
  data->incomeRange = incomeRange->GetSelIndex();
  return TDialog::CanClose();
}


0
 

Author Comment

by:gurumike
Comment Utility
Excellent.  I used CleanupWindow() and it worked perfectly.  All of my questions have been answered - thank you for your time and your help!!

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now