How do I hide a column in a wxListCtrl?

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
geddy
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Mar 31, 2008 6:23 am

How do I hide a column in a wxListCtrl?

Post by geddy » Wed Apr 02, 2008 2:10 am

Hi all

How do I hide a column in a wxListCtrl?

Thanks

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Wed Apr 02, 2008 6:12 am

Hi,
set column's width to zero.

Code: Select all

    list->SetColumnWidth(n, 0);
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

geddy
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Mar 31, 2008 6:23 am

Post by geddy » Thu Apr 03, 2008 5:25 am

hi
But user can resize the column width. I want to hide some columns in wxListCtrl, but user can resize other columns

mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r » Thu Apr 03, 2008 5:51 am

geddy wrote:hi
But user can resize the column width. I want to hide some columns in wxListCtrl, but user can resize other columns
Add a handler for the column size event EVT_LIST_COL_BEGIN_DRAG(id, func) and veto it for columns you don't want the user to be able to resize. ie... the hidden ones.

-Max

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Thu Apr 03, 2008 6:10 am

Hi,
geddy wrote:hi
But user can resize the column width. I want to hide some columns in wxListCtrl, but user can resize other columns
yes, but you can disable resizing of the particular columns.

Code: Select all

...
    EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL_ID, MyListCtrl::OnColBeginDrag)
...

m_zero_width_column_num = 1;
m_list->SetCoumnWidth(m_zero_width_column_num, 0);

...

void MyListCtrl::OnColBeginDrag(wxListEvent& event)
{
    if ( event.GetColumn() == m_zero_width_column_num )
    {
        event.Veto();
    }
}

OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Thu Apr 03, 2008 6:43 am

Removing and adding columns on the fly works pretty well, too.

Something like this (I have a virtual wxListrCtrl in report mode).

Code: Select all

void ServiceListCtrl::RebuildColumns() {
	int nColumns = GetConfiguredColumnCount();
	int nCurrentColumns = GetColumnCount();
	if (nCurrentColumns > nColumns) {
		while (nCurrentColumns > nColumns) {
			DeleteColumn(nCurrentColumns--);
		}
	} else if (nCurrentColumns < nColumns) {
		while (nCurrentColumns < nColumns) {
			InsertColumn(nCurrentColumns, 
				GetColumnLabel(nCurrentColumns), 
				wxLIST_FORMAT_LEFT, 
				wxLIST_AUTOSIZE_USEHEADER);
			nCurrentColumns++;
		}
	}
}

geddy
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Mar 31, 2008 6:23 am

Post by geddy » Tue Apr 08, 2008 3:57 am

Thank you for your enthusiastic help! That's help me a lot!

Post Reply