Discussion:
CListBox - MultiColumn's - How to ??
(too old to reply)
Jay
2005-03-05 01:30:52 UTC
Permalink
Hi All
I am trying to create a 4 column ListBox .
I have added the ListBox to the Dialog & set the MultiColumn
property there.

Using the following names could someone give me some code to,
1/ Create 4 Columns in the ListBox
2/ Load "some data" into each column in row 0

Name : ListBox
Control Variable : m_ctrlList
String Variable :m_strList

Any help is much appreciated as I am not having much luck
with MSDN or the web,


Jay
Frank Hickman [MVP]
2005-03-05 04:11:10 UTC
Permalink
Post by Jay
Hi All
I am trying to create a 4 column ListBox .
I have added the ListBox to the Dialog & set the MultiColumn
property there.
Using the following names could someone give me some code to,
1/ Create 4 Columns in the ListBox
2/ Load "some data" into each column in row 0
Name : ListBox
Control Variable : m_ctrlList
String Variable :m_strList
Any help is much appreciated as I am not having much luck
with MSDN or the web,
Jay
Very basic example...

BOOL CDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// <snip> removed all the MFC generated code for a dialog based app...

// TODO: Add extra initialization here

m_ctrlList.InsertColumn( 0, _T("Column 1"), LVCFMT_LEFT, 100 );
m_ctrlList.InsertColumn( 1, _T("Column 2") ); // Default
formatting...

m_ctrlList.InsertItem( 0, _T("Item One") );
m_ctrlList.SetItemText( 0, 1, _T("SubItem One") );


m_ctrlList.InsertItem( 1, _T("Item Two") );
m_ctrlList.SetItemText( 1, 1, _T("SubItem Two") );

m_ctrlList.InsertItem( 2, _T("Item Three") );
m_ctrlList.SetItemText( 2, 1, _T("SubItem Three") );

return TRUE; // return TRUE unless you set the focus to a control
}
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the ***@m_ with @ to reply.
Joseph M. Newcomer
2005-03-05 05:34:13 UTC
Permalink
Actually, you answered the question for a list control, which is what I think he really
wants anyway. He is thinking a multicolumn listbox is something other than what it really
is, which is a listbox which has multiple columns to display single top-level data. So my
advice was going to be that he should use a list control--so you've already answered that.
joe
Post by Frank Hickman [MVP]
Post by Jay
Hi All
I am trying to create a 4 column ListBox .
I have added the ListBox to the Dialog & set the MultiColumn
property there.
Using the following names could someone give me some code to,
1/ Create 4 Columns in the ListBox
2/ Load "some data" into each column in row 0
Name : ListBox
Control Variable : m_ctrlList
String Variable :m_strList
Any help is much appreciated as I am not having much luck
with MSDN or the web,
Jay
Very basic example...
BOOL CDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// <snip> removed all the MFC generated code for a dialog based app...
// TODO: Add extra initialization here
m_ctrlList.InsertColumn( 0, _T("Column 1"), LVCFMT_LEFT, 100 );
m_ctrlList.InsertColumn( 1, _T("Column 2") ); // Default
formatting...
m_ctrlList.InsertItem( 0, _T("Item One") );
m_ctrlList.SetItemText( 0, 1, _T("SubItem One") );
m_ctrlList.InsertItem( 1, _T("Item Two") );
m_ctrlList.SetItemText( 1, 1, _T("SubItem Two") );
m_ctrlList.InsertItem( 2, _T("Item Three") );
m_ctrlList.SetItemText( 2, 1, _T("SubItem Three") );
return TRUE; // return TRUE unless you set the focus to a control
}
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Frank Hickman [MVP]
2005-03-05 06:46:20 UTC
Permalink
Post by Joseph M. Newcomer
Actually, you answered the question for a list control, which is what I think he really
wants anyway. He is thinking a multicolumn listbox is something other than what it really
is, which is a listbox which has multiple columns to display single top-level data. So my
advice was going to be that he should use a list control--so you've already answered that.
joe
Good eye Joe, I didn't catch that, obviuosly :)
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the ***@m_ with @ to reply.
Jay Cee
2005-03-05 18:35:12 UTC
Permalink
Thank you Frank & Joe
Its a good thing you both knew what I wanted !!!

Works perfectly and explained in an easy sample.

Regards,

Jay
Post by Frank Hickman [MVP]
Post by Joseph M. Newcomer
Actually, you answered the question for a list control, which is what I think he really
wants anyway. He is thinking a multicolumn listbox is something other than what it really
is, which is a listbox which has multiple columns to display single top-level data. So my
advice was going to be that he should use a list control--so you've
already answered that.
joe
Good eye Joe, I didn't catch that, obviuosly :)
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Loading...