wxDataviewListCtrl - change choice box contents 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
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

wxDataviewListCtrl - change choice box contents

Post by Widgets »

I'm trying to use a data view list control with some rows of a column having a choice box.
During the initial setup, when I set the column headings I add a choice box column without data. For most rows, this is just fine, but for some rows I would like to add a number of different choices - possibly different choices for some rows, but not for each and every other row.

Is this possible with data view list control or should/must I be using a grid or some other control?

TIA
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataviewListCtrl - change choice box contents

Post by ONEEYEMAN »

Hi,
Did you look at the sample?

Thank you.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxDataviewListCtrl - change choice box contents

Post by Manolo »

wxDataViewCtrl is designed so a type of value (text, bitmap, etc) is associated with a column for all rows.

To have different behaviour for each row is hard. First you need your own wxDataViewModel and your own wxDataViewCustomRenderer.

In the model you define the type, wxString in your case.
Having a string in a row and a bitmap in the same column but different row is also posible (I think). The type is converted and passed among model/renderer through a wxVariant type. So I guess you can have type "wxString" and convert the value to something that makes sense for you.

renderer::SetValue() and renderer::GetValue() pass the wxVariant in the cell. Thus, your model must store the current value: The string in the wxChoice or the string in the not-wxChoice case. If all choices are the same for all rows you can derive from wxDataViewChoiceByIndexRenderer.

renderer::Render() is the key. Parameters are the rectangle coordinates and the DC for this cell. You can draw into that DC whatever you like.

The other key is the group of renderer-editor funcs: HasEditorCtrl(), CreateEditorCtrl() and GetValueFromEditorCtrl() which allow you to create a wxChoice control.

wxDVC lacks a good sample and docs. If you dig into generic implementation and run with a lot of breaks in the code you will learn how it works internally. Good luck.
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Re: wxDataviewListCtrl - change choice box contents

Post by Widgets »

Manolo wrote:wxDataViewCtrl is designed so a type of value (text, bitmap, etc) is associated with a column for all rows.

To have different behaviour for each row is hard. First you need your own wxDataViewModel and your own wxDataViewCustomRenderer.
Thank you. Manolo.
For this time and this project, adapting the whole seems to be too much work. It is the first time I had tried to use this type of control to learn more about it. Since it is only part of a dialog used every so often to set base parameters, I think I will be able to manage with a grid.
I had gotten all of the rest to work - and it is a lot of fiddly stuff, because the control has a lot of features - though not all I would need :-) - but when it came to the part of possibly having a different set of strings for the choice box in different rows that I ran into issues.
By the time I asked, I had more or less concluded that the renderer was an 'attribute' of the whole column, but wanted to be sure there would not be an relatively easy way to handle this case.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
Post Reply