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
wxDataviewListCtrl - change choice box contents Topic is solved
wxDataviewListCtrl - change choice box contents
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
Re: wxDataviewListCtrl - change choice box contents
Hi,
Did you look at the sample?
Thank you.
Did you look at the sample?
Thank you.
Re: wxDataviewListCtrl - change choice box contents
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.
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.
Re: wxDataviewListCtrl - change choice box contents
Thank you. Manolo.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.
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
MSVC Express 2019/2022
wxWidgets 3.2.2