wxDataViewListCtrl - Is it possible to hide certain columns? Topic is solved
wxDataViewListCtrl - Is it possible to hide certain columns?
Is it possible to hide/show certain column in wxDataViewListCtrl inside the application as needed, like for example this screenshot of my file manager,
As you can see, when I right click on the column headers, I get option to show/hide certain columns, is it possible to do so? Also if it is possible, can I still get the value and all about that column when it is hidden?
As you can see, when I right click on the column headers, I get option to show/hide certain columns, is it possible to do so? Also if it is possible, can I still get the value and all about that column when it is hidden?
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Catch wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
Display popup
Use wxSettableHeaderColumn::SetHidden( bool flag ) to set visibility
Display popup
Use wxSettableHeaderColumn::SetHidden( bool flag ) to set visibility
Use the source, Luke!
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Okay, I tried what you told me, I was to able to make it work, but how do I make it so each menu entry is dedicated to the specific column that the menu item text corresponds to?
Here is what I wrote, I set the binding for it,
Code: Select all
Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &MainFrame::OnShowSampleListColumnHeaderContextMenu,
this, BC_SampleListView);
Code: Select all
void MainFrame::OnShowSampleListColumnHeaderContextMenu(wxDataViewEvent& event)
{
wxMenu menu;
wxSettableHeaderColumn* setHeaderCol = event.GetDataViewColumn();
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites");
menu.AppendCheckItem(MN_ColumnFilename, "Filename");
menu.AppendCheckItem(MN_ColumnSamplePack, "Sample Pack");
menu.AppendCheckItem(MN_ColumnType, "Type");
menu.AppendCheckItem(MN_ColumnChannels, "Channels");
menu.AppendCheckItem(MN_ColumnLength, "Length");
menu.AppendCheckItem(MN_ColumnSampleRate, "Sample Rate");
menu.AppendCheckItem(MN_ColumnBitrate, "Bitrate");
menu.AppendCheckItem(MN_ColumnPath, "Path");
switch (m_SampleListView->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_ColumnFavorite:
if (menu.IsChecked(MN_ColumnFavorite))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnFilename:
if (menu.IsChecked(MN_ColumnFilename))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnSamplePack:
if (menu.IsChecked(MN_ColumnSamplePack))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnType:
if (menu.IsChecked(MN_ColumnType))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnChannels:
if (menu.IsChecked(MN_ColumnChannels))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnLength:
if (menu.IsChecked(MN_ColumnLength))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnSampleRate:
if (menu.IsChecked(MN_ColumnSampleRate))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnBitrate:
if (menu.IsChecked(MN_ColumnBitrate))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
case MN_ColumnPath:
if (menu.IsChecked(MN_ColumnPath))
setHeaderCol->SetHidden(true);
else
setHeaderCol->SetHidden(false);
break;
default:
break;
}
}
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Code: Select all
wxSettableHeaderColumn* setHeaderCol = event.GetDataViewColumn();
You need to way to get the correct wxDataViewColumn for each ID like MN_ColumnFilename.
You can get a pointer to a wxDataViewColumn with wxDataViewCtrl::GetColumn(int pos)
When creating the menu checkitems you should also check all entries for the columns that are currently visible ( wxHeaderColumn::IsShown() )
Use the source, Luke!
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
I see, if I understand correctly, it should be like this, I have commented out the path column, as it does not exist right now.doublemax wrote: ↑Mon Jun 28, 2021 5:54 amYou don't need this, the column you clicked on doesn't matter.Code: Select all
wxSettableHeaderColumn* setHeaderCol = event.GetDataViewColumn();
You need to way to get the correct wxDataViewColumn for each ID like MN_ColumnFilename.
You can get a pointer to a wxDataViewColumn with wxDataViewCtrl::GetColumn(int pos)
When creating the menu checkitems you should also check all entries for the columns that are currently visible ( wxHeaderColumn::IsShown() )
Code: Select all
void MainFrame::OnShowSampleListColumnHeaderContextMenu(wxDataViewEvent& event)
{
wxMenu menu;
// wxSettableHeaderColumn* setHeaderCol = event.GetDataViewColumn();
wxDataViewColumn* FavoriteColumn = m_SampleListView->GetColumn(0);
wxDataViewColumn* FilenameColumn = m_SampleListView->GetColumn(1);
wxDataViewColumn* SamplePackColumn = m_SampleListView->GetColumn(2);
wxDataViewColumn* TypeColumn = m_SampleListView->GetColumn(3);
wxDataViewColumn* ChannelsColumn = m_SampleListView->GetColumn(4);
wxDataViewColumn* LengthColumn = m_SampleListView->GetColumn(5);
wxDataViewColumn* SampleRateColumn = m_SampleListView->GetColumn(6);
wxDataViewColumn* BitrateColumn = m_SampleListView->GetColumn(7);
// wxDataViewColumn* PathColumn = m_SampleListView->GetColumn(8);
if (FavoriteColumn->IsShown())
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(true);
else
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(false);
if (FilenameColumn->IsShown())
menu.AppendCheckItem(MN_ColumnFilename, "Filename")->Check(true);
else
menu.AppendCheckItem(MN_ColumnFilename, "Filename")->Check(false);
if (SamplePackColumn->IsShown())
menu.AppendCheckItem(MN_ColumnSamplePack, "Sample Pack")->Check(true);
else
menu.AppendCheckItem(MN_ColumnSamplePack, "Sample Pack")->Check(false);
if (TypeColumn->IsShown())
menu.AppendCheckItem(MN_ColumnType, "Type")->Check(true);
else
menu.AppendCheckItem(MN_ColumnType, "Type")->Check(false);
if (ChannelsColumn->IsShown())
menu.AppendCheckItem(MN_ColumnChannels, "Channels")->Check(true);
else
menu.AppendCheckItem(MN_ColumnChannels, "Channels")->Check(false);
if (LengthColumn->IsShown())
menu.AppendCheckItem(MN_ColumnLength, "Length")->Check(true);
else
menu.AppendCheckItem(MN_ColumnLength, "Length")->Check(false);
if (SampleRateColumn->IsShown())
menu.AppendCheckItem(MN_ColumnSampleRate, "Sample Rate")->Check(true);
else
menu.AppendCheckItem(MN_ColumnSampleRate, "Sample Rate")->Check(false);
if (BitrateColumn->IsShown())
menu.AppendCheckItem(MN_ColumnBitrate, "Bitrate")->Check(true);
else
menu.AppendCheckItem(MN_ColumnBitrate, "Bitrate")->Check(false);
// if (PathColumn->IsShown())
// menu.AppendCheckItem(MN_ColumnPath, "Path")->Check(true);
// else
// menu.AppendCheckItem(MN_ColumnPath, "Path")->Check(false);
switch (m_SampleListView->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
{
case MN_ColumnFavorite:
if (menu.IsChecked(MN_ColumnFavorite))
FavoriteColumn->SetHidden(false);
else
FavoriteColumn->SetHidden(true);
break;
case MN_ColumnFilename:
if (menu.IsChecked(MN_ColumnFilename))
FilenameColumn->SetHidden(false);
else
FilenameColumn->SetHidden(true);
break;
case MN_ColumnSamplePack:
if (menu.IsChecked(MN_ColumnSamplePack))
SamplePackColumn->SetHidden(false);
else
SamplePackColumn->SetHidden(true);
break;
case MN_ColumnType:
if (menu.IsChecked(MN_ColumnType))
TypeColumn->SetHidden(false);
else
TypeColumn->SetHidden(true);
break;
case MN_ColumnChannels:
if (menu.IsChecked(MN_ColumnChannels))
ChannelsColumn->SetHidden(false);
else
ChannelsColumn->SetHidden(true);
break;
case MN_ColumnLength:
if (menu.IsChecked(MN_ColumnLength))
LengthColumn->SetHidden(false);
else
LengthColumn->SetHidden(true);
break;
case MN_ColumnSampleRate:
if (menu.IsChecked(MN_ColumnSampleRate))
SampleRateColumn->SetHidden(false);
else
SampleRateColumn->SetHidden(true);
break;
case MN_ColumnBitrate:
if (menu.IsChecked(MN_ColumnBitrate))
BitrateColumn->SetHidden(false);
else
BitrateColumn->SetHidden(true);
break;
// case MN_ColumnPath:
// if (menu.IsChecked(MN_ColumnPath))
// PathColumn->SetHidden(false);
// else
// PathColumn->SetHidden(true);
// break;
default:
break;
}
}
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Code: Select all
if (FavoriteColumn->IsShown())
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(true);
else
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(false);
Code: Select all
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check( FavoriteColumn->IsShown() );
Shouldn't the item menu only open on right click?It does work though, but I'm having a little problem, I have a context menu for the rows as well, when I right click on a column header, and select a item, the column header menu closes, and the row menu opens immediately.
Use the source, Luke!
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Sounds like this recently fixed bug:doublemax wrote: ↑Mon Jun 28, 2021 7:18 amShouldn't the item menu only open on right click?It does work though, but I'm having a little problem, I have a context menu for the rows as well, when I right click on a column header, and select a item, the column header menu closes, and the row menu opens immediately.
https://github.com/wxWidgets/wxWidgets/ ... 925f569a39
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
I see, thanks for the suggestion. I'll switch my statements to this.doublemax wrote: ↑Mon Jun 28, 2021 7:18 amThis could also be written as:Code: Select all
if (FavoriteColumn->IsShown()) menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(true); else menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check(false);
Same goes for the SetHidden() calls later.Code: Select all
menu.AppendCheckItem(MN_ColumnFavorite, "Favorites")->Check( FavoriteColumn->IsShown() );
It only opens on right click, this only started happening after adding the menu for column header.doublemax wrote: ↑Mon Jun 28, 2021 7:18 amShouldn't the item menu only open on right click?It does work though, but I'm having a little problem, I have a context menu for the rows as well, when I right click on a column header, and select a item, the column header menu closes, and the row menu opens immediately.
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
I see, is this fix for wx3.0.x or wx3.1.x? I'm currently using wx3.0.5.PB wrote: ↑Mon Jun 28, 2021 7:57 amSounds like this recently fixed bug:doublemax wrote: ↑Mon Jun 28, 2021 7:18 amShouldn't the item menu only open on right click?It does work though, but I'm having a little problem, I have a context menu for the rows as well, when I right click on a column header, and select a item, the column header menu closes, and the row menu opens immediately.
https://github.com/wxWidgets/wxWidgets/ ... 925f569a39
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
The commit says it is in the master. I did not check if it was backported, AFAIK the chance of 3.0.6 being released is not that high anyway.
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
So for me only way to get this issue fixed is switching to wx version 3.1.x?
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
The patch is trivial and should also apply to wx 3.0.x. So you could make the few changes yourself and rebuild your wx libraries.
However, upgrading to the latest wx version would be a good idea anyway.
However, upgrading to the latest wx version would be a good idea anyway.
Use the source, Luke!
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
I see, I'll think about what to do. Thanks for the help
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Just confirming, the master branch on https://github.com/wxWidgets/wxWidgets repository is the wx3.1.x stable version right? I'm thinking providing a link to the repository as a dependency for my project, because no Linux distribution I know currently ships wx3.1.x in their repositories. Or if there is a better/good way to handle this dependency please let me know.
Re: wxDataViewListCtrl - Is it possible to hide certain columns?
Technically all odd subversion numbers (2.7.x, 2.9.x, 3.1.x, etc) are not stable, these are development versions. The even numbers (2.8.x, 3.0.x, etc) are stable. However stable here does not mean that it doesn't crash, it means that the API is stable, e.g. there won't be any incompatible API changes between 3.0.6 and 3.0.7. In terms of reliability the development version is safe to use for production code (IMHO).
Use the source, Luke!