5

I'm working on a program, which should list all files and it's size(for now...). I created a simple application, which should write the data to a listbox. I'm trying to write the data in two columns(the first should be the name, and next to it, in an other column, it's size), but i can't figure out, how should i do this. Can someone help me?

Thanks in advance!

kampi

Update:

I try to use ListControl., but unfortunately i can't. I can succesfully compile my App, but i can only see, the empty rectangle. Does someone know what i am doing wrong?

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

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon

// TODO: Add extra initialization here

LVITEM lvItem;
LVCOLUMN lvColumn;
int nCol;

lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvColumn.fmt = LVCFMT_CENTER;
lvColumn.cx = 10;
lvColumn.pszText = _T("Filename");
ListView_InsertColumn( m_List, 0, &lvColumn ); 
ListView_SetItemText( m_List, 0, 0, _T("TEST") );

return TRUE;  // return TRUE  unless you set the focus to a control    
}

4 Answers 4

4

The list box control does support multiple columns, but it only supports a single series of entries; the multiple column support just makes the items continue onto the next columns so that vertical scrolling is not necessary.

As Kornel has suggested, a list view control may be more appropriate. After creating a list view control, use ListView_InsertColumn to create the columns. Then use ListView_SetItemText to insert items.

EDIT: My apoligies; you should use ListView_InsertItem to insert an item (a row) and then use ListView_SetItemText to alter the subitems (columns). If the list view is still just a blank box without any headings, have you initialised common controls? This can be done using InitCommonControlsEx, specifying the ICC_LISTVIEW_CLASSES constant. This should be done before creating the control.

See Microsoft's documentation on list view controls.

1
  • Hi! Thank you very much for your help! I forgot to initialize the common controls. Thanks, again!
    – kampi
    Jan 30, 2010 at 19:33
3

Don't use a List Box, use a List Control with LVS_REPORT style.

1
  • Hi!This looks very good! Thanks! I tried it out, but it doesn't show anything in it. I can see only, the white rectangle. What i am doing wrong?
    – kampi
    Jan 30, 2010 at 3:04
0

Maybe to use DataGridView with object as data source.

0

Three important parameters to be checked are

  1. List Box or the List Control (List Control is to be used)
  2. View parameter must be Report mode
  3. Owner Data must be set to False The screenshot shows these enter image description here

The programming flow to add data to list control are Change the list Control to extended list view(ListView_SetExtendedListViewStyle), Create the layout(By adding columns), Add Item data (for each row needed) & add finally add sub-item to each column (for each item data added previously).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.