How Do I Append Column to wxDataViewListCtrl? 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.
Post Reply
Dafarkias
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Apr 26, 2021 7:57 pm

How Do I Append Column to wxDataViewListCtrl?

Post by Dafarkias » Wed May 05, 2021 4:41 pm

Hey there!

Dafarkias here. Back with more questions :D

For the life of me, I can't figure out how to append/insert a column into my wxDataViewListCtrl after I've initially populated it with items. I spent all last evening messing with this, and now am still stuck this morning, unfortunately :?

My project is getting fairly sizeable so I will try and piece together the code bits I am attempting to use, to assist with any potential helpful diagnostics.

First I create my wxDataViewListCtrl.

Code: Select all

g_list = new MyDataView(w_panelTop); g_list->SetSize(0, 0, w(), 200);
Then populate it with items, using code that looks roughly like this (all of these in "for" loops to create a table):

Code: Select all

g_list->AppendTextColumn(temper2[i].substr(0, tEnd), wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);

...

data.push_back(wxString::Format(st2wx(items[b])));
glist->AppendItem(data, NULL);
This works fine, and I am able to create a large table of different columns, and rows/items.

When I go to insert or append a new column, I run into issues:

Image

I have tried to add new columns many different ways, but my latest attempt I use a code snippet I pulled straight from the docs:

Code: Select all

        wxVector<wxVariant> data;
        g_list->AppendTextColumn("New Column");
        data.push_back(wxVariant("row 1"));
        g_list->AppendItem(data); // this line of code is performed in a "for" loop, equal to the number of columns
        data.clear();
Any help would be great! [-o<

[edit]

I'd like to clarify from the error code that I am 99% positive that the issue is not my attempting to input an incorrect number of data indexes when using AppendItem. I have verified that the number of data indexes match the number of columns when debugging, and I'm using the same code I use to initially populate the table, which works just fine

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5152
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How Do I Append Column to wxDataViewListCtrl?

Post by ONEEYEMAN » Wed May 05, 2021 5:07 pm

Hi,
What kind of data you plan to store in this column?
What platform you are using? What wx version?

Thank you.

Dafarkias
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Apr 26, 2021 7:57 pm

Re: How Do I Append Column to wxDataViewListCtrl?

Post by Dafarkias » Wed May 05, 2021 5:17 pm

Just string data. My current project loads up data from a text file and then populates the columns and items.

I'm using Windows 10, wxWidget 3.1.4 with Visual Studio 2019

User avatar
doublemax
Moderator
Moderator
Posts: 16012
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How Do I Append Column to wxDataViewListCtrl?

Post by doublemax » Wed May 05, 2021 5:36 pm

The assert message is pretty clear. If you add another column, you must make sure that the control has data for it. For all lines, including the ones that are already there.
Use the source, Luke!

Dafarkias
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Apr 26, 2021 7:57 pm

Re: How Do I Append Column to wxDataViewListCtrl?

Post by Dafarkias » Wed May 05, 2021 5:48 pm

My mistake. I assumed append worked differently.

Nevertheless, I've tried code previously that deleted all columns and items and attempted to resupply the data in its entirety, and also had no luck.

When I changed the code, like you mentioned, to supply the control with 7 points of data (6 columns + the new append column) I now trigger a breakpoint in appbase.cpp, line 1163:

Code: Select all

static void
wxDefaultAssertHandler(const wxString& file,
                       int line,
                       const wxString& func,
                       const wxString& cond,
                       const wxString& msg)
{
    // If this option is set, we should abort immediately when assert happens.
    if ( wxSystemOptions::GetOptionInt("exit-on-assert") )
        wxAbort();

    // FIXME MT-unsafe
    static int s_bInAssert = 0;

    wxRecursionGuard guard(s_bInAssert);
    if ( guard.IsInside() )
    {
        // can't use assert here to avoid infinite loops, so just trap
        wxTrap();

        return;
    }

    if ( !wxTheApp )
    {
        // by default, show the assert dialog box -- we can't customize this
        // behaviour
        ShowAssertDialog(file, line, func, cond, msg);
    }
    else
    {
        // let the app process it as it wants
        // FIXME-UTF8: use wc_str(), not c_str(), when ANSI build is removed
        wxTheApp->OnAssertFailure(file.c_str(), line, func.c_str(),
                                  cond.c_str(), msg.c_str());
    }
}
The error comes from the line: wxTrap, apparently.

User avatar
doublemax
Moderator
Moderator
Posts: 16012
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How Do I Append Column to wxDataViewListCtrl?

Post by doublemax » Wed May 05, 2021 10:22 pm

So is this your post? https://groups.google.com/g/wx-users/c/313ouk4R8HU

Would be quite a coincidence if two different people have exactly the same problem at the same time.
Use the source, Luke!

Dafarkias
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Apr 26, 2021 7:57 pm

Re: How Do I Append Column to wxDataViewListCtrl?

Post by Dafarkias » Thu May 06, 2021 2:07 pm

Ha!

That is funny, because that actually is not my post. So I figured out my problem with the help of you both (thank you very much). It was due to a fault in logic (of course). With my very limited programming experience I'm not used to dealing with things that aren't very "user friendly."

The problem was that I was trying to add new items/rows without deleting the previous items/rows. Rookie mistake.

I do have another question, may I ask it here, or do I need to create a new thread?

I'm having difficulty getting a wxDataViewColumn from EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK.

For instance, when I right-click the column header, and it triggers the event, what if I want to delete the column? How do I get the specific wxDataViewColumn pointer from the event?

User avatar
doublemax
Moderator
Moderator
Posts: 16012
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How Do I Append Column to wxDataViewListCtrl?

Post by doublemax » Thu May 06, 2021 2:23 pm

I'm having difficulty getting a wxDataViewColumn from EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK.

For instance, when I right-click the column header, and it triggers the event, what if I want to delete the column? How do I get the specific wxDataViewColumn pointer from the event?
wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK generates a wxDataViewEvent, which has methods like wxDataViewEvent::GetColumn(), or wxDataViewEvent::GetDataViewColumn()

https://docs.wxwidgets.org/trunk/classw ... event.html
Use the source, Luke!

Dafarkias
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Apr 26, 2021 7:57 pm

Re: How Do I Append Column to wxDataViewListCtrl?

Post by Dafarkias » Thu May 06, 2021 3:35 pm

Fantastic!

=P~

Thanks again!

Post Reply