CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2009
    Posts
    14

    ComboBox as child of a ListCtrl in a FormView

    Hello!

    In an application I have a Form View with a list control (m_ctrlList) in it, among others. The list control is set to report style. There is also a combo box that is supposed to show up, whenever I click particular items in the list control. The combo box is hence created as a child of the list control.

    Code:
    dwStyle =  WS_BORDER|WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST;
    m_ctrlCombo.Create(dwStyle, r, &m_ctrlList, IDC_INPUT_COMBO);
    So far so good. The combo box shows where and when i want it.

    Now I want to handle a selection change of the combo box within the form view class and there's my problem: Since the combo box is a child of the list control the form view class doesn't get a message when the selection is changed...

    I inserted a message map entry like this:

    Code:
    ON_CBN_SELCHANGE(IDC_INPUT_COMBO, &CInputView::OnCbnSelchangeInputCombo)
    Any ideas?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ComboBox as child of a ListCtrl in a FormView

    Did you try to handle it in the CListCtrl derived class?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2009
    Posts
    14

    Re: ComboBox as child of a ListCtrl in a FormView

    I avoided deriving my own list control. The combo box is also a member of the CFormView derived class but created as the list control's child.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ComboBox as child of a ListCtrl in a FormView

    Quote Originally Posted by maglite View Post
    I avoided deriving my own list control.
    Why?
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2009
    Posts
    14

    Re: ComboBox as child of a ListCtrl in a FormView

    Well, I thought it would save me some work - obviously without thinking about the trouble it could get me in.

    But that's not the whole reason. I have a doc-view application with multiple views which communicate with each other. So, if I change the combo boxes selection I need the form view to recognize it and call the document's UpdateAllViews method. Therefore I thought it would be more comfortable to just let the combo box be a member of the view and directly handle a selection change...
    Last edited by maglite; June 15th, 2009 at 04:50 AM.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ComboBox as child of a ListCtrl in a FormView

    Quote Originally Posted by maglite View Post
    Well, I thought it would save me some work - obviously without thinking about the trouble it could get me in.
    What *trouble* do you mean? I never had any trouble while using classes derived from MFC control classes.

    Quote Originally Posted by maglite View Post
    ... I have a doc-view application with multiple views which communicate with each other. So, if I change the combo boxes selection I need the view to send a message to the other views.
    Hmmm... It is not the best way to communicate between the Views.
    The best (and it is the standard one) is using CDocument::UpdateAllViews method.

    Quote Originally Posted by maglite View Post
    ... I thought it would be more comfortable to just let the combo box be a member of the view and directly handle a selection change...
    But being the *member* of the View does NOT mean being its *child* which is needed to send the notifications to the View (notifications are sent to the parent window.)
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2009
    Posts
    14

    Re: ComboBox as child of a ListCtrl in a FormView

    What *trouble* do you mean? I never had any trouble while using classes derived from MFC control classes.
    I meant the trouble that results in NOT deriving my own class but doing it the way I did.

    Hmmm... It is not the best way to communicate between the Views.
    The best (and it is the standard one) is using CDocument::UpdateAllViews method.
    Using CDocument::UpdateAllViews is what I meant by communication. I should have been more exact.

    But being the *member* of the View does NOT mean being its *child* which is needed to send the notifications to the View (notifications are sent to the parent window.)
    I'm aware of this fact and already identified it as my problem in the initial post.

    So your suggestion is to derive my own list control and let it send a message to the view, when the combo's selection is changed?
    Last edited by maglite; June 15th, 2009 at 05:23 AM.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ComboBox as child of a ListCtrl in a FormView

    Yiou can get some ideas from this article
    Victor Nijegorodov

  9. #9
    Join Date
    Jun 2009
    Posts
    14

    Re: ComboBox as child of a ListCtrl in a FormView

    Alright. Thank you for now. I'm going to derive my own list control and let you know if it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured