CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2002
    Posts
    18

    Combo box in a list control?!?!

    I'm still pretty new to MFC and all it's features... so now I need all the help I can find!

    I have a simple list control in a dialog box. One of the column must be a drop down list (combo box). What's the EASIEST way to do so?!

    I've seen a lot of ways so far but they all look soooooo complicated!

    I really need help here!

    Thanx!
    -= Nasty_p =-

  2. #2
    Join Date
    Aug 2002
    Posts
    18

    Anybody???

    I could really need a hand here folks!

    -= Nasty_p =-

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757
    There are several possible solutions and none is easy. One is custom-draw. The second require you to derive a class from CListCtrl and do your own drawing.

    Kuphryn

  4. #4
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    The way to put a combo box into a list control is to fake it!!

    You can figure out when the mouse clicks on the list control right?

    You can figure out which record in the list the mouse clicks on right?

    You can even figure out which feild in the list control was clicked on right?

    You then can figure out the height of the list entry.

    You then can figure out the width and the screen dementions of the list entry...

    Ok now put it all together... Conceptually your combo box won't be part of the list control so much as resized, re-initialized with the new drop down values, moved to the right location on the list control, and then marked visible...

    When you lay out you're window put a combo box onto the screen. go to the properties section of the combo box and leave the window hidden.. Now you've got your combo box to use for the operation...

    Now when you detect the mouse click on the hot field,

    1) populate the combo box with the correct entires...

    2) use MoveWindow() call to size the combo box and move it into the correct location, you can also mark it to visible in this same call. Figuring out the coordinents of the field and the coordinents of where to move the combo box is most of the complexity in this seemingly complex technique..

    Ok so you're half way home... Now you've got to figure out if

    1) you're list control looses focus. In this case if a combo box is visible you need to invis the combo box and sync the selected entry in the combo box with that in the list control field..

    2) Figure out if someone clicks on a different list control field.. here do the same thing as in step 1...

    3) if they click on the same field only a different record.. remember to hide and sync before you move..

    You get the idea, a little noodleing and you can get it to work perfect.... be sure to make a class around your list control object, so you can encapsolate some of this functionality into that class. .

    Good luck...

  5. #5
    Join Date
    Aug 2002
    Posts
    18

    Thumbs up Kool!!!

    Great!!!

    I forged something out of what you explained and it worked! Thanx a lot! Really appreciate it!!!

    You gotta admit that it ain't no piece of cake though!

    Long lives codeguru.com!
    -= Nasty_p =-

  6. #6
    Join Date
    Aug 2002
    Posts
    18

    Unhappy Oh no! I've created a new problem!

    In my dialog class I had the handler "OnDblclkProblem" ('cause the list is a list of problems...) which looked like this:

    void CIa_tariferDlg::OnDblclkProblem(NMHDR* pNMHDR, LRESULT* pResult)
    {
    OnModifyProb();
    *pResult = 0;
    }

    ...and everything was fine! Everytime I double clicked on an item from the list, something would happen.

    But then I created another class "CListProbCtrl" from the base class "CListCtrl" to help me create the combobox-in-a-list effect. In my "CListProbCtrl" class I have the handler "OnLButtonDown" which enables me to make the combobox appear whenever a click on a particular area of the list. It looks like this:

    void CListExigCtrl::OnLButtonDown(UINT nFlags, CPoint point)
    {
    CListCtrl::OnLButtonDown(nFlags, point);

    int index;
    CListCtrl::OnLButtonDown(nFlags, point);

    int colnum;
    if ((index = SelectColumn(point, &colnum)) != -1)
    {
    UINT flag = LVIS_FOCUSED;
    if ((GetItemState(index, flag) & flag) == flag)
    {
    // Add check for LVS_EDITLABELS
    if (GetWindowLong(m_hWnd, GWL_STYLE) && LVS_EDITLABELS)
    {
    if (colnum == 3)
    {
    CStringList lstItems;
    lstItems.AddTail("A VOIR");
    lstItems.AddTail("VU ");
    ShowList(index, colnum, lstItems, 0);
    }
    }
    }
    else
    SetItemState (index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
    }
    }

    ...but now the problem is that I CAN NO LONGUER CATCH THE DOUBLE CLICK MESSAGE!!! Why is that? Everytime I double click on one of the items from the list now.... nothing happens! I'm only able to get my combobox.... whitch is great, but I really need both!!!

    Again... I'm asking for help from the pros!!!

    Thanx!
    -= Nasty_p =-

  7. #7
    Join Date
    Aug 2002
    Posts
    18

    Still... anyone?

    Promess this will be the last post guys!
    -= Nasty_p =-

  8. #8
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by kuphryn
    There are several possible solutions and none is easy. One is custom-draw. The second require you to derive a class from CListCtrl and do your own drawing.

    Kuphryn
    There is an easy solution. Just look at the CodeGuru articles about list controls (I think it is the listview section).
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #9
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by JMS
    2) use MoveWindow() call to size the combo box and move it into the correct location, you can also mark it to visible in this same call. Figuring out the coordinents of the field and the coordinents of where to move the combo box is most of the complexity in this seemingly complex technique..
    As I mentioned in my previous reply, there is a CodeGuru article with this already coded; at least most of it.

    I used the CodeGuru sample of providing an edit control to make cells editable and then I also wanted a combobox type of solution. I realized that a combobox is by definition a combination of edit box and list box. In my case the choices needed to be limited to the values provided so I just used the existing list control cell with a lit box underneath. That worked well.

    I had one problem in that if I used the wrong parent of the edit control or list control then there were numerous problems. So for those that want to do it themself or want to enhance existing samples, just be aware that using the correct parent is important. I forget what is the correct parent but I think it is the dialog that must be the parent. I think I thought it would be better to make the list control the parent and I think that is where I had a problem.

    I also thought it would be better to allow the list box to extend past the dialog's border. I think I got that working also but I must admit I never finished the entire project. However it is true that getting the list box or combobox positioned properly it can be complicated.

    I think the most complicated thing was getting the arrow keys to work the way I wanted them to so that it was most logical and convenient for the user and yet so that my editing capability was intiated and terminated as it should be.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  10. #10
    Join Date
    Aug 2002
    Posts
    18

    Smile

    Found my other problem!!!
    I was calling "OnLButtonDown" twice:

    void CListExigCtrl::OnLButtonDown(UINT nFlags, CPoint point)
    {
    CListCtrl::OnLButtonDown(nFlags, point);

    int index;
    CListCtrl::OnLButtonDown(nFlags, point);

    int colnum;
    if ((index = SelectColumn(point, &colnum)) != -1)
    .....

    Ho! Is my face red!!

    Thanx again!!!
    -= Nasty_p =-

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