Documentation typo - wxListColumnFormat (Issue #24548)

16 views
Skip to first unread message

aureliencc

unread,
May 21, 2024, 8:00:30 AMMay 21
to wx-...@googlegroups.com, Subscribed

Hello,

I think I found a typo in the documentation, the description for "wxListColumnFormat" is :

Column format (MSW only except wxLIST_FORMAT_LEFT)

Source : https://docs.wxwidgets.org/latest/interface_2wx_2listctrl_8h.html#afddccbb0d7cf18f9b205f00efc5738d0

But I guess it should have been :

Column format (MSW only accept wxLIST_FORMAT_LEFT)

As none of the others values seems to work on Windows.

Regards,


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548@github.com>

PB

unread,
May 21, 2024, 8:50:24 AMMay 21
to wx-...@googlegroups.com, Subscribed

Column alignment works in wxListCtrl report mode on Windows:
wx-listctrl-col-alignment.png (view on web)

Code
#include <wx/wx.h>
#include <wx/listctrl.h>

class MyApp : public wxApp
{
public:   
    bool OnInit() override
    {
        wxFrame* frame = new wxFrame(nullptr, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 600));

        wxListCtrl* listCtrl = new wxListCtrl(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
        listCtrl->AppendColumn("Left", wxLIST_FORMAT_LEFT);
        listCtrl->AppendColumn("Centre", wxLIST_FORMAT_CENTRE);
        listCtrl->AppendColumn("Right", wxLIST_FORMAT_RIGHT);
            
        listCtrl->InsertItem(0, "Short");
        listCtrl->SetItem(0, 1, "Short");
        listCtrl->SetItem(0, 2, "Short");

        listCtrl->InsertItem(1, "Very looooooong");
        listCtrl->SetItem(1, 1, "Very looooooong");
        listCtrl->SetItem(1, 2, "Very looooooong");

        listCtrl->SetColumnWidth(0, wxLIST_AUTOSIZE);
        listCtrl->SetColumnWidth(1, wxLIST_AUTOSIZE);
        listCtrl->SetColumnWidth(2, wxLIST_AUTOSIZE);
        
        frame->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122564117@github.com>

aureliencc

unread,
May 21, 2024, 9:53:10 AMMay 21
to wx-...@googlegroups.com, Subscribed

Hello @PBfordev,

Thank you for your reply.

I'm using wxLC_REPORT | wxLC_VIRTUAL flags and I was not able to make it work on my system.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122691597@github.com>

VZ

unread,
May 21, 2024, 10:10:58 AMMay 21
to wx-...@googlegroups.com, Subscribed

I think the documentation is indeed wrong, but only because alignment is supported under all platforms and not just in wxMSW.

As for alignment not working for you, please try to reproduce the problem with the minimal changes to the listctrl sample and open a separate issue for it. Thanks!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122730274@github.com>

aureliencc

unread,
May 21, 2024, 10:23:34 AMMay 21
to wx-...@googlegroups.com, Subscribed

The following minimal wxListCtrl view example works :

`
#include
#include
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/listctrl.h>

// =================================
class List : public wxListCtrl {

public:
List(wxWindow* parent);
wxString OnGetItemText(long item, long column) const;
void AddAStr(const std::string& s);

private:
void Update();

std::vector<std::string> m_list{};

};

// =================================

List::List(wxWindow* parent)
: wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
{
AppendColumn(L"LEFT", wxLIST_FORMAT_LEFT);
AppendColumn(L"CENTRE", wxLIST_FORMAT_CENTRE);
AppendColumn(L"RIGHT", wxLIST_FORMAT_RIGHT);
}

wxString List::OnGetItemText(long item, long column) const
{
if (item < 0 || item >= m_list.size()) {
return "invalid index";
}
switch (column) {
case 0:
case 1:
case 2: { return m_list[item]; } break ;
default: { return "invalid column"; }
}
}

void List::Update()
{
SetItemCount(m_list.size());
Refresh();
}

void List::AddAStr(const std::string& s)
{
m_list.push_back(s);
Update();
}
// =================================

class MyApp : public wxApp
{
bool OnInit() override
{
auto* frame = new wxFrame(nullptr, wxID_ANY, "foo", wxDefaultPosition, wxDefaultSize);

    auto* m_list_view{ new List(frame) };
    m_list_view->AddAStr("A long str");
    m_list_view->AddAStr("A long str");
    m_list_view->AddAStr("A long str");
    m_list_view->AddAStr("A long str");
    m_list_view->AddAStr("A long str");
    m_list_view->AddAStr("A long str");
    frame->Show(true);

    return true;
}

}; wxIMPLEMENT_APP(MyApp);

`

Unfortunately, I cannot get it to work in my project. I only have one column, I want it to be centered.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122757233@github.com>

VZ

unread,
May 21, 2024, 10:25:02 AMMay 21
to wx-...@googlegroups.com, Subscribed

Sorry, but you really need to provide a simple example showing what does not work to allow understanding what the problem is, I don't see any point in showing a working example.

If you can do it, please create a new issue with such example. Thanks!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122760281@github.com>

aureliencc

unread,
May 21, 2024, 10:25:37 AMMay 21
to wx-...@googlegroups.com, Subscribed

The following minimal wxListCtrl view example works :

#include <vector>
#include <string>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
#include <wx/listctrl.h>

// =================================
class List : public wxListCtrl {

public:
    List(wxWindow* parent);
    wxString OnGetItemText(long item, long column) const;
    void AddAStr(const std::string& s);

private:
    void Update();

    std::vector<std::string> m_list{};
};

// =================================

List::List(wxWindow* parent)
    : wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
{
    AppendColumn(L"LEFT", wxLIST_FORMAT_LEFT);
    AppendColumn(L"CENTRE", wxLIST_FORMAT_CENTRE);
    AppendColumn(L"RIGHT", wxLIST_FORMAT_RIGHT);
}

wxString List::OnGetItemText(long item, long column) const
{
    if (item < 0 || item >= m_list.size()) {
        return "invalid index";
    }
    switch (column) {
        case 0:
        case 1:
        case 2: { return m_list[item]; } break ;
        default: { return "invalid column"; }
    }
}

void List::Update()
{
    SetItemCount(m_list.size());
    Refresh();
}

void List::AddAStr(const std::string& s)
{
    m_list.push_back(s);
    Update();
}
// =================================

class MyApp : public wxApp
{
        bool OnInit() override
    {
        auto* frame = new wxFrame(nullptr, wxID_ANY, "foo", wxDefaultPosition, wxDefaultSize);

        auto* m_list_view{ new List(frame) };
        m_list_view->AddAStr("A long str");
        m_list_view->AddAStr("A long str");
        m_list_view->AddAStr("A long str");
        m_list_view->AddAStr("A long str");
        m_list_view->AddAStr("A long str");
        m_list_view->AddAStr("A long str");
        frame->Show(true);

        return true;
    }
}; wxIMPLEMENT_APP(MyApp);


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122761369@github.com>

PB

unread,
May 21, 2024, 10:40:12 AMMay 21
to wx-...@googlegroups.com, Subscribed

After testing, it seems that the right or center alignment does not work in the very first column, which is always aligned to the left, regardless of requested alignment.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122792743@github.com>

aureliencc

unread,
May 21, 2024, 10:48:47 AMMay 21
to wx-...@googlegroups.com, Subscribed

This is a known issue : https://forums.wxwidgets.org/viewtopic.php?t=6675

I'm sorry, I did not found this topic while debugging.

Thank you for your help,


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122810811@github.com>

aureliencc

unread,
May 21, 2024, 10:48:47 AMMay 21
to wx-...@googlegroups.com, Subscribed

Closed #24548 as completed.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/24548/issue_event/12881385389@github.com>

PB

unread,
May 21, 2024, 11:02:30 AMMay 21
to wx-...@googlegroups.com, Subscribed

Ah, sorry, this is the limitation of the native control, but as noted, can be worked around:
https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-lvcolumna#remarks
wx-listctrl-col-alignment.png (view on web)

Minimal Code
#include <wx/wx.h>
#include <wx/listctrl.h>

class List : public wxListCtrl
{
public:
    List
(wxWindow* parent)
        : wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL)
    {
        AppendColumn("LEFT", wxLIST_FORMAT_LEFT);
        AppendColumn("CENTRE", wxLIST_FORMAT_CENTRE);

        DeleteColumn(0);
        SetItemCount(5);
    }

    wxString OnGetItemText(long item, long column) const override
    {
        return wxString::Format("C%ld I%ld", column, item);
    }
};

class MyApp : public wxApp
{
    bool OnInit() override
    {
        wxFrame* frame = new wxFrame(nullptr, wxID_ANY, "Test Frame");
        new List(frame);
        frame->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24548/2122840723@github.com>

Reply all
Reply to author
Forward
0 new messages