Need Syntax for setting a "choice" inside wxDataViewListCtrl
Posted: Wed Jul 12, 2017 10:23 pm
Hi. I am creating a wxDataViewListCtrl object using wxCrafter in CodeLite. My wxDataViewListCtrl object contains three columns of different types:
Column 0 is type int.
Column 1 is type "check".
Column 2 is type "choice." The possible values are: apple;banana;cantaloupe;date;eggplant;fig;grape
I have two questions.
1. I have set Column 1's Cell Mode to wxDATAVIEW_CELL_EDITABLE. However, the cell is grayed during execution. Does another flag have to be set for it to be editable? See the screen shot below.
2. I can't figure out how to initialize the values in Column 2 to anything. I can display a number in that column, but I want to display the text string corresponding to that number in the choices list. I.e. display "apple" instead of 0; display "banana" instead of 1; and so on.
What is the syntax to assign a value to a "choice" column in a wxDataViewListCtrl? See my attempts to figure out syntax in the code below.
I can also run the program, and double-click the field, and change its value in the drop-down. But I don't know how to give the field a value in code.
To solve this problem, I looked at the sample code in C:\wxWidgets\samples\dataview\dataview.cpp. I am using wxCrafter, though, and I don't know if I'm supposed to create a wxDataViewChoiceRenderer, or if that's done inside wxCrafter.
Thanks in advance for your help.
Colleen
Column 0 is type int.
Column 1 is type "check".
Column 2 is type "choice." The possible values are: apple;banana;cantaloupe;date;eggplant;fig;grape
I have two questions.
1. I have set Column 1's Cell Mode to wxDATAVIEW_CELL_EDITABLE. However, the cell is grayed during execution. Does another flag have to be set for it to be editable? See the screen shot below.
2. I can't figure out how to initialize the values in Column 2 to anything. I can display a number in that column, but I want to display the text string corresponding to that number in the choices list. I.e. display "apple" instead of 0; display "banana" instead of 1; and so on.
What is the syntax to assign a value to a "choice" column in a wxDataViewListCtrl? See my attempts to figure out syntax in the code below.
Code: Select all
#include "MainFrame.h"
#include <wx/aboutdlg.h>
MainFrame::MainFrame(wxWindow* parent)
: MainFrameBaseClass(parent)
{
#define QTY_ROWS 16
#define QTY_FRUITS 7
bool b = false;
int i = 0;
int j = 0;
unsigned int row = 0;
unsigned int col = 0;
wxString Row_St = "";
wxString Msg_St = "";
wxVector<wxVariant> cols;
// This is a wxDataViewListCtrl with three columns:
//
// 0 1 2
// Index | Check or Uncheck | Fruits
// | |
// | |
//
// where the type of each is:
// Index: int
// Check or Uncheck: check
// Fruits is a choice. Its values are:
//
// apple
// banana
// cantaloupe
// date
// eggplant
// fig
// grape
for (i = 0; i < QTY_ROWS; i++)
{
cols.clear (); // Clear this buffer.
// Column 0: Index
Row_St = wxString::Format ("%2d", i);
cols.push_back (Row_St);
// Column 1: Check or Uncheck
b = (bool) ((i % 3) < 2);
row = (unsigned int) i + 1; // row 0 is the column header row, so skip it
col = (unsigned int) 1;
// m_dvListCtrl11->SetToggleValue (b, row, col);
cols.push_back (b);
// Column 2: Fruits
// What is the syntax to access a specific column's choice value?
j = i % QTY_FRUITS;
Row_St = wxString::Format ("What is the syntax to display choice #%d?", j);
cols.push_back (b);
m_dvListCtrl11->AppendItem (cols);
m_dvListCtrl11->Refresh (true);
}
// Practice editing fields manually....
m_dvListCtrl11->SetValue (false, (unsigned int) 1, (unsigned int) 1);
m_dvListCtrl11->SetValue (false, (unsigned int) 2, (unsigned int) 1);
m_dvListCtrl11->SetValue (false, (unsigned int) 3, (unsigned int) 1);
m_dvListCtrl11->SetValue (true, (unsigned int) 4, (unsigned int) 1);
m_dvListCtrl11->SetValue (false, (unsigned int) 5, (unsigned int) 1);
m_dvListCtrl11->SetValue (false, (unsigned int) 6, (unsigned int) 1);
m_dvListCtrl11->SetValue (false, (unsigned int) 7, (unsigned int) 1);
// m_dvListCtrl11->SetValue ((Fruits) 3, (unsigned int) 7, (unsigned int) 2); // syntax error
// m_dvListCtrl11->SetValue ((m_dvListCtrl11->Fruits) 3, (unsigned int) 7, (unsigned int) 2); // syntax error
m_dvListCtrl11->SetValue (3, (unsigned int) 7, (unsigned int) 2); // prints "3", not "date"
}
MainFrame::~MainFrame()
{
}
void MainFrame::OnExit(wxCommandEvent& event)
{
wxUnusedVar(event);
Close();
}
void MainFrame::OnAbout(wxCommandEvent& event)
{
wxUnusedVar(event);
wxAboutDialogInfo info;
info.SetCopyright(_("My MainFrame"));
info.SetLicence(_("GPL v2 or later"));
info.SetDescription(_("Short description goes here"));
::wxAboutBox(info);
}
void MainFrame::OnDvlistctrl11DataviewItemValueChanged(wxDataViewEvent& event)
{
}
void MainFrame::OnDvlistctrl11DataviewSelectionChanged(wxDataViewEvent& event)
{
}
To solve this problem, I looked at the sample code in C:\wxWidgets\samples\dataview\dataview.cpp. I am using wxCrafter, though, and I don't know if I'm supposed to create a wxDataViewChoiceRenderer, or if that's done inside wxCrafter.
Thanks in advance for your help.
Colleen
Code: Select all
Software Versions
CodeLite 10.0.6
MinGW hard to tell the version I have, but I downloaded it "fresh" on July 10, 2017.
Windows 10 Pro, 64-bit
wxWidgets 3.0.2
wxCrafter 2.6
Target platform 32-bit
Target build debug