|
It does appear as if we are having trouble communicating...
DavidCrow wrote: This appears to be the root of the confusion. For a combobox having the CBS_DROPDOWNLIST style, there is no edit control. It's actually a static control.
In Drop List style, the edit box does not go away.
It is still there but it is static and will not accept user text and a mouse click opens the dropdown. When you select an item in the dropdown, the control inserts the text you selected (apparently employing SelectString and WM_SETTEXT) into the now "static" edit box (one would think if it were truly static that it would not change ata all).
It is this inserted text I hope to clear in Drop List style.
DavidCrow wrote: What control is this message targeted for?
According the Spy++, the CCombobox control sends the WM_SETTEXT message as the last event in my OnSelchange function. Since the message begins with "WM_, I believe that means that it is a windows message, and I assume that it is sent to the parent dialog in which the combobox control exists and plays a role in the painting of the text in the control's edit box.
DavidCrow wrote: Is the edit box a separate control that you are updating based on the combobox selection?
You appear to suggest that the edit box associated with the combobox we have been discussing becomes a separate control when it is in Drop List mode.
I suppose that it is possible for the edit box to change to a different control when one changes the control's style, but I find it difficult to believe that just changing a combobox's style turns it into two separate controls.
Thank you for all your assistance. I have managed to find a satisfactory workaround using the DropDown style. While I would prefer to use the Drop List, I can live with what I have now - and will revisit this problem again later.
Thanks again.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: ...(one would think if it were truly static that it would not change ata all).
It's definitely a static control and not an edit control that has been merely made read-only. You can confirm this via Spy++. The "combo" part comes from it being a listbox coupled with either a static control or an edit control. What the control is comprised of is irrelevant, however.
lctrncs wrote: It is this inserted text I hope to clear in Drop List style.
Why? If the user selected it from the combobox, why clear it? Would that not be ultimately confusing? How would they then know what, if anything, has been selected? I've never seen a combobox behave in this fashion. Do you have an example?
lctrncs wrote: You appear to suggest that the edit box associated with the combobox we have been discussing becomes a separate control when it is in Drop List mode.
No, it simply does not exist. Furthermore, I don't recall ever having to interact with a combobox in this way. Once a selection has been made, it stays "made" until the list is dropped down and some other selection is made.
lctrncs wrote: I find it difficult to believe that just changing a combobox's style turns it into two separate controls.
A combobox has always been two-controls-in-one, even back with Windows 3.x.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am using the combobox as a method for selecting records in a database. Since the record is displayed once the user selects the text, there is no longer a need to display duplicate information in the combobox - and it looks funky if it remains displayed.
While I thought I had a useful workaround earlier, I am not as happy with it now as I thought I would be.
I never was one to do things the same way as everyone else, so my unique approach to the combobox does not surprise me that much. I thought about tree controls and list boxes, but I need something that remains hidden most of the time.
So what do you think about painting over the edit control to hide the selected text, or trapping the WM_SETTEXT?
I am very tired and would very much like to find a solution soon. I have been trying to solve this problem for a very long time!
Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: I am using the combobox as a method for selecting records in a database.
Why not use a list control?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I do not have very much real estate in my database dialog. I like the idea of having a one line control open up to display a multiline area for the selection of records. If I went with the list control, I would need a much larger dialog and my users would have to fool around with scroll bars more.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Would it be possible to break your dialog up into multiple pages and use a property sheet?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I suppose it would be possible. However, I am trying to keep things simple and user friendly.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Following what I think you are trying to do, you are using the wrong control. ComboBoxes are designed to select an option and display it until the selection is changed. Clearing it goes against what it was designed for. You should either use a ListBox or a List Control for what I think you are trying to do.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for responding.
I wish that a list box would meet my needs!
There is not much real estate on my dialog so the drop down window is very attractive.
In addition, the list of record data is only visible when you want to see it, making the dialog look better (less "busy" and confusing).
If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: If the Combobox was not designed to have the edit box cleared, how come it has the member Clear()?
To clear any "selected" text from the control. Are you selecting the text prior to calling the Clear() method?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yes.
I select the text with:
pCombo->SetEditSel(0,-1);
Interestingly, I have found that
pCombo->SetEditSel(0,-1);<br />
pCombo->Clear();
does not work as well as
pCombo->SetEditSel(0,-1);<br />
pCombo->Paste();<br />
pCombo->SetEditSel(0,-1);<br />
pCombo->Clear();
while this is effective - it not cosmetically pleasing.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: In drop list mode my OnSelchangeCombo function...
What does this method look like?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
What does my OnSelChangeCombo function look like?
It is rather simple:
1. Pointer to the Combobox with assert if NULL,
2. code to return index of selected item in listbox from control directed alpha listing (thank you Chris Losinger!),
3. dirtyflag check of record and associated commit if true,
4. call of the GotoRecord function.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Ok, what I have here may help, or it may not since it is not entirely like what you have. I have a CRecordset -derived class that reads from the Employees table of the Northwind database. I have a dialog with a combobox (having the CBS_DROPDOWNLIST style) and listbox. Selecting an item from the combobox will add it to the listbox. The selection in the combobox is then cleared.
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CDatabase db;
CSet rs(&db);
rs.Open();
while (! rs.IsEOF())
{
m_combo.AddString(rs.m_LastName);
rs.MoveNext();
}
rs.Close();
m_combo.InsertString(0, "");
return TRUE;
}
void CMyDlg::OnSelchangeCombo1()
{
int nIndex = m_combo.GetCurSel();
CString strItem;
m_combo.GetLBText(nIndex, strItem);
m_list.AddString(strItem);
m_combo.SetCurSel(0);
} Is this close?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Well I got things running like you show here - the Class Wizard info was key - but it still does not clear the edit box in either dropdown or drop list mode - any other suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
If you can narrow this project down to just the relevant lines, you can e-mail it to me and I'll take a look.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank you.
I spent some time with it this weekend and got it working.
Thank You!
Your assistance was of great service to me!
Thank you again!
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Overall, what did you do to finally get it going?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem.
Being a complete beginner, this is the first time I have tried to instantiate a class and my local resource (an embedded systems programmer) cannot provide much assistance.
The class (CCombobox) and member (InsertString) I am using are overridden.
When I instantiate an instance like this
OverRiddenCombobox w_wndOverBox;
locally in the function where I want to use it (along with
w_wndOverBox InsertString(0,"",0)
, my program compiles and runs fine until I try to open the dialog.
Then I get and exception error, and the debuger shows me a line in afxwin.inl apparently defining the not overridden base class member InsertSting with two arguments (my InsertString has three arguments).
Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: I am beginning to wonder if my use of the dereference operator rather than the dot operator might be part of my problem.
Use -> with pointers, and a . (dot) otherwise. The compiler should warn you of incorrect usage.
lctrncs wrote: w_wndOverBox InsertString(0,"",0)
What's holding w_wndOverBox and InsertString() apart?
lctrncs wrote: Then I get and exception error, and the debuger shows me a line in afxwin.inl...
An exception or an assertion?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: What's holding w_wndOverBox and InsertString() apart?
A dot operator (sorry about the incorrect post).
DavidCrow wrote: An exception or an assertion?
An assertion:
Debug Assertion Failed...
_AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString)<br />
{ ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: An assertion:
Debug Assertion Failed...
_AFXWIN_INLINE int CCombobox::InsertString(int nIndex, LPCTSTR lpszString)
{ ASSERT(::IsWindow(m_hWnd)); return (int)::Sendmessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString); }
Which indicates you have a non-existent window. At what point are you trying to populate the combobox?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I populate the combobox in OnInitDialog - which is only called upon dialog start and after a change to the database such as adding or deleting a record.
I am trying to clear the dropdown style edit box (drop list style would be preferred due to the static edit box) from my DisplayRecord function (called at the end of OnInitDialog), and this is where I have instantiated m_wndComboBox, and from where I call m_wndComboBox.InsertString(0,"",0).
The control exists on a modeless dialog, which is trying to open at the time of the assert.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: ...this is where I have instantiated m_wndComboBox...
m_wndComboBox should be a member variable, not local to some function.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
As I said, I have never tried to instantiate a class instance so that I can use the dot operator.
I tried to instantiate it in a number of locations (mainframe.cpp main.c etc.) without success.
So where should I instantiate my m_wndCombobox so that I can use the dot operator as you suggest
m_combo.InsertStinrg(0,"")
?
Why should the dot operator work when a pointer does not?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|