How to create a multi-column list?

I am working on a program in which all files and size should be indicated (at the moment ...). I created a simple application that should write data to a list. I am trying to write data in two columns (the first should be the name, and next to it, in the other column, the size), but I can’t understand how I should do it. Can anybody help me?

Thanks in advance!

Kampi

Update:

I am trying to use ListControl., But unfortunately I cannot. I can successfully compile my application, but I only see an empty rectangle. Does anyone know what I'm doing wrong?

BOOL CGetFileListDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application 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
source share
4 answers

The list control supports multiple columns, but only supports one series of records; multi-column support just makes items continue in the next columns, so vertical scrolling is not required.

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

EDIT: My apolygias; you should use ListView_InsertItem to insert an item (row), and then use ListView_SetItemText to change subitems (columns). If the list view is still just an empty titleless field, have you initialized the common controls? This can be done using InitCommonControlsEx , specifying the constant ICC_LISTVIEW_CLASSES . This must be done before creating the control.

See Microsoft Documentation for List View Items .

+4
source

Do not use the list box, use List Control using the LVS_REPORT style.

+2
source

It is possible to use a DataGridView with an object as a data source.

0
source

Three important parameters to check:

  • List box or list control (list control should be used)
  • View must be in report mode
  • Owner data must be set to False. A screenshot shows these enter image description here

Programming flow for adding data to a list control: change the Control list to an extended list ( ListView_SetExtendedListViewStyle ), create a layout (by adding columns), add item data (for each row required), and finally add a sub-item for each column ( for each item added previously).

0
source

Source: https://habr.com/ru/post/1299800/


All Articles