wxcombobox with several rows Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

wxcombobox with several rows

Post by Wolfgang »

I have a comboboax which is filled with app. 60 items, what I need is that all are shown at once, so it should have multiple columns.

Is that somehow possible?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxcombobox with several rows

Post by ONEEYEMAN »

Hi,
Are you looking for wxListBox?

Thank you.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

Not really:

What I want, the selected should stand in the ctrl, like it is by the combobox.
However when i click on it and all the options get shown, it should not only be one column, it should be multiple colums. As there are a lot of values, it should be splitted into more colums.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxcombobox with several rows

Post by PB »

I believe wxComboBox does not support this feature out of the box (nor does the underlying native control on MSW).

However, you can use a list view with a wxComboCtrl: bundled combo sample actually has it on display.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

Thanks for the combo ctrl advice,that works.
Also I have some questions for it.

How can I manage that it will automatically extend to show all items?
And how can I place a line between the colums?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxcombobox with several rows

Post by ONEEYEMAN »

Hi,
Can you show some code?
Are you using wxListView in report mode?

Thank you.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

I did take it out of the combo example
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

Code: Select all

class ListViewComboPopup  : public wxListView, public wxComboPopup
{
public:

    virtual void Init() wxOVERRIDE
    {
        m_value = -1;
        m_itemHere = -1; // hot item in list
    }

    virtual bool Create(wxWindow* parent) wxOVERRIDE
    {
        return wxListView::Create(parent, 1,
            wxPoint(0, 0), wxDefaultSize,
            wxLC_LIST | wxLC_SINGLE_SEL |
           wxSIMPLE_BORDER);
    }

    virtual wxWindow* GetControl() wxOVERRIDE { return this; }

    virtual void SetStringValue(const wxString& s) wxOVERRIDE
    {
        int n = wxListView::FindItem(-1, s);
        if (n >= 0 && n < GetItemCount())
            wxListView::Select(n);
    }

    virtual wxString GetStringValue() const wxOVERRIDE
    {
        if (m_value >= 0)
            return wxListView::GetItemText(m_value);
        return wxEmptyString;
    }

    //
    // Popup event handlers
    //

    // Mouse hot-tracking
    void OnMouseMove(wxMouseEvent& event)
    {
        // Move selection to cursor if it is inside the popup

        int resFlags;
        int itemHere = HitTest(event.GetPosition(), resFlags);
        if (itemHere >= 0)
        {
            wxListView::Select(itemHere, true);
            m_itemHere = itemHere;
      


        }
        event.Skip();
    }

    // On mouse left, set the value and close the popup
    void OnMouseClick(wxMouseEvent& event)
    {
        m_value = m_itemHere;
        wxInt16 mywin;
        mywin = event.GetId();
        if (mywin == 9190)
        {
            wxString test;
            test = "he";

        }
        else if (mywin == 9191)
        {
            wxString test;
            test = "he";

        }
        else if (mywin == 9192)
        {
            wxString test;
            test = "he";

        }
        else if (mywin == 9193)
        {
            wxString test;
            test = "he";
        }
        // TODO: Send event
        Dismiss();
    }

    //
    // Utilies for item manipulation
    //

    void AddSelection(const wxString& selstr)
    {
        wxListView::InsertItem(GetItemCount(), selstr);
    }

protected:

    int             m_value; // current item index
    int             m_itemHere; // hot item in popup

private:
    wxDECLARE_EVENT_TABLE();
};

Code: Select all

class wxComboCtrlWithCustomPopupAnim : public wxComboCtrl
{


protected:
    virtual bool AnimateShow(const wxRect & rect, int WXUNUSED(flags)) wxOVERRIDE
    {
        wxWindow* win = GetPopupWindow();
        win->SetSize(rect);
        win->Raise();  // This is needed
        win->ShowWithEffect(wxSHOW_EFFECT_BLEND);
        return true;
    }
};

Code: Select all

wxBEGIN_EVENT_TABLE(ListViewComboPopup, wxListView)
EVT_MOTION(ListViewComboPopup::OnMouseMove)
// NOTE: Left down event is used instead of left up right now
//       since MSW wxListCtrl doesn't seem to emit left ups
//       consistently.
EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick)
wxEND_EVENT_TABLE()

Code: Select all

    //verse
    lv_vname = new wxComboCtrlWithCustomPopupAnim();
    lv_vname->SetTextCtrlStyle(wxTE_RIGHT);
    lv_vname->Create(tb1);
    lv_vname->UseAltPopupWindow();
    lv_vname->SetId(ID_lv_vname);
    lv_vname->SetPopupMinWidth(100);
    lv_vname->SetInitialSize(wxSize(60, 30));
    iface_vn = new ListViewComboPopup();
    lv_vname->SetPopupControl(iface_vn);
    wxComboCtrl::GetFeatures();
    count = 1;
     while (count<=maxkap)
    {
        wxString newh;
        newh << count;
        iface_vn->AddSelection(newh);
        count++;
    }
    iface_vn->Fit();
    help = "";
    help << suvnr[jetwin] - 1;
    iface_vn->Select(wxAtoi(help), true);
    lv_vname->SetText(help);
    tb1->AddControl(lv_vname);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxcombobox with several rows

Post by ONEEYEMAN »

Hi,
You list view needs to be in report mode. Then you will have lines between columns.
And maybe you sizing issue will be fixed as well.

Thank you.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

in report mode I did get the background visible, so that each item background is only white as big as the item is. there was no other changes, and in overall it was not showing so smooth.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxcombobox with several rows

Post by ONEEYEMAN »

Hi,
Not sure what you mean.
Can you make a screenshot?

Also, what platform are you testing it on?

Thank you.
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Mon Jan 28, 2019 8:22 am

Re: wxcombobox with several rows

Post by Wolfgang »

I'm using windows.

One problem I found in listview, the popup does not get automatically bigger as the initial ctrl, what i need.

Screenshots only later, will be away until tomorrow evening.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxcombobox with several rows

Post by PB »

Wolfgang wrote: Sun Sep 29, 2019 4:29 amOne problem I found in listview, the popup does not get automatically bigger as the initial ctrl, what i need.
But you can (1) compute the ideal list size since you know the item count and can get item rects and (2) set the pop-up size, can't you?

OTOH, I would have thought that report mode was not suitable when the columns should contain only items and not subitems: one would not be able to select the items (i.e., "cells"), only whole rows.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxcombobox with several rows

Post by ONEEYEMAN »

@PB,
The OP wanted the divider between the columns.
Maybe it is possible to somehow get the column for the row selected?

I didn't look at the API too close.

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxcombobox with several rows

Post by PB »

ONEEYEMAN wrote: Mon Sep 30, 2019 5:23 pm The OP wanted the divider between the columns.
Maybe it is possible to somehow get the column for the row selected?
I know that the OP wants the column separator; however, I believe that this cannot be really achieved with a wxLC_LIST wxListCtrl. And if wxLC_REPORT is used: one can get the item clicked as the programmer, but as the user, I would find odd that I can highlight only an item group (= row) and not an individual item...
Post Reply