Dave's Brain

Browse - programming tips - win32 multicolumn listbox

Date: 2008jul9
Language: C/C++
Platform: win32, MFC

Q.  How do you make a multicolumn listbox?

A.  In the resource set LB_SETTABSTOPS and add strings with tabs.
(Or you can use a listctrl in report mode.)

// We first setup these two small functions

inline BOOL ListBoxSetTabStops(const HWND hdlg, const int id, const int cTabs, const LPINT nTabs)
{
	return SendDlgItemMessage(hdlg, id, LB_SETTABSTOPS, (WPARAM) cTabs, (LPARAM) nTabs);
}

inline int ListBoxAddString(const HWND hdlg, const int id, LPCSTR s)
{
	return SendDlgItemMessage(hdlg, id, LB_ADDSTRING, 0, (LPARAM) s);
}

void ExampleUse()
{
  	int	nTabs[] = { 100, 200 };

   	ListBoxSetTabStops(hDlg, IDC_MYLISTBOX, 2, nTabs);
   	ListBoxAddString(hDlg, IDC_MYLISTBOX, "one\ttwo\tthree");
}

//---------------------------------------------
// In MFC:

void ExampleUse()
{
  	int	nTabs[] = { 100, 200 };

	m_Mylistbox.SetTabStops(2, nTabs);
	m_Mylistbox.AddString("one\ttwo\tthree");
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: