Hello all,
if I add a new item to a wxDataViewListCtrl with wxDataViewListCtrl::AppendItem, how am I supposed to get its row number? Unfortunately all the insert or append methods seem to return void...
Right now I'm using wxDataViewListCtrl::GetItemCount, but that doesn't feel right. After all, the documentation doesn't even guarantee that the row numbering actually starts with zero. Without that guarantee I can't reliably get the row number from the count.
Regards
Jorg
wxDataViewListCtrl: How to officially get the row number of a new item
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: wxDataViewListCtrl: How to officially get the row number of a new item
wxDataViewListCtrl::ItemToRow()
https://docs.wxwidgets.org/trunk/classw ... ad30be241f
There is also RowToItem()
https://docs.wxwidgets.org/trunk/classw ... ad30be241f
There is also RowToItem()
Re: wxDataViewListCtrl: How to officially get the row number of a new item
That's not really helpful, because it begs the question: How do I get that wxDataViewItem? The only way seems to be via RowToItem() which brings me back to the original question.doublemax@work wrote: ↑Tue May 25, 2021 11:33 am wxDataViewListCtrl::ItemToRow()
https://docs.wxwidgets.org/trunk/classw ... ad30be241f
There is also RowToItem()
Re: wxDataViewListCtrl: How to officially get the row number of a new item
Hi,
How do you add the row/item to the control?
Thank you.
How do you add the row/item to the control?
Thank you.
Re: wxDataViewListCtrl: How to officially get the row number of a new item
Hi,
Can you give the exact code?
Thank you.
Can you give the exact code?
Thank you.
Re: wxDataViewListCtrl: How to officially get the row number of a new item
Sure. Nothing really special:
Code: Select all
void AppendMsg(const TextMessageWrapper::pointer_type &msgptr) {
auto tp_to_str = [](const std::chrono::system_clock::time_point &tp) -> std::string {
std::stringstream ss;
#if 0
using namespace date;
local_time<std::chrono::seconds> ltp = tp;
ss << format("%D %T %Z", floor<std::chrono::seconds>(tp));
return ss.str();
#else
std::time_t tt = std::chrono::system_clock::to_time_t(tp);
std::tm tm = *std::localtime(&tt);
ss << std::put_time(&tm, "%X");
return ss.str();
#endif
};
wxVector<wxVariant> data;
data.push_back(wxVariant(wxString::FromUTF8(msgptr->getMessage()->get_subject())));
data.push_back(wxVariant(std::to_string(msgptr->getMessage()->get_message_id())));
data.push_back(wxVariant(ack_to_str(msgptr->is_acked())));
data.push_back(wxVariant(tp_to_str(msgptr->get_rx_time())));
data.push_back(wxVariant(tp_to_str(msgptr->getMessage()->get_timestamp())));
m_owner->m_msg_data_view->AppendItem(data, msgptr->get_local_id());
msgptr->set_dataview_row(m_owner->m_msg_data_view->GetItemCount() - 1);
}
Code: Select all
wxDataViewListCtrl* m_msg_data_view;
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: wxDataViewListCtrl: How to officially get the row number of a new item
Sorry, i naturally assumed that AppendItem() returns a wxDataViewItem. Apparently it doesn't and looking through the API i don't see any other way than your solution.
Re: wxDataViewListCtrl: How to officially get the row number of a new item
I have raised the topic in the wx-users list: https://groups.google.com/g/wx-users/c/ ... 6FXa82AgAJdoublemax@work wrote: ↑Tue May 25, 2021 2:23 pm Sorry, i naturally assumed that AppendItem() returns a wxDataViewItem. Apparently it doesn't and looking through the API i don't see any other way than your solution.