Solved

ListView

Posted on 2001-07-29
1
183 Views
Last Modified: 2013-11-20
I want to use list control and dynamically add items.
I want if I have five colums to divide equally the control display area with the five columns with no horizontal scroll bar showing or no extra space left. How should I do that. Give me an exmample code for three items. Just the columns is OK.
Thanks
0
Comment
Question by:jc64
1 Comment
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6333070
Here ya go!

void CD6Dlg::OnButton1()
{
    CRect rc;
    m_clcList.GetWindowRect( &rc );

    int nListWidth= rc.Width();

    // --- if you expect a vertical scrollbar...
    int nScrollBarWide= GetSystemMetrics( SM_CXVSCROLL );
    nListWidth -= nScrollBarWide;
   
    int nClmWide = nListWidth/CNUM_ClmCnt;
    int nLastClmWide= nClmWide;
    while ( nLastClmWide + (nClmWide * (CNUM_ClmCnt-1)) < nListWidth-1 ) {
        nLastClmWide++;
    }
    nClmWide     -= 1;  // divider width
    nLastClmWide -= 1;
   
    m_clcList.InsertColumn(     0, "Clm A", LVCFMT_LEFT, nClmWide );
    m_clcList.InsertColumn(     1, "Clm B", LVCFMT_LEFT, nClmWide );
    m_clcList.InsertColumn(     2, "Clm C", LVCFMT_LEFT, nClmWide );
    m_clcList.InsertColumn(     3, "Clm D", LVCFMT_LEFT, nClmWide );
    m_clcList.InsertColumn(     4, "Clm E", LVCFMT_LEFT, nLastClmWide );

    m_clcList.InsertItem(  0,    "Item A0" );
    m_clcList.SetItemText( 0, 1, "Item B0" );
    m_clcList.SetItemText( 0, 2, "Item C0" );
    m_clcList.SetItemText( 0, 3, "Item D0" );
    m_clcList.SetItemText( 0, 4, "Item E0" );

    m_clcList.InsertItem(  1,    "Item A1" );
    m_clcList.SetItemText( 1, 1, "Item B1" );
    m_clcList.SetItemText( 1, 2, "Item C1" );

    m_clcList.InsertItem(  2,    "Item A2" );
    m_clcList.SetItemText( 2, 1, "Item B2" );
    m_clcList.SetItemText( 2, 2, "Item C2" );

    m_clcList.InsertItem(  3,    "Item A3" );
    m_clcList.SetItemText( 3, 1, "Item B3" );
    m_clcList.SetItemText( 3, 2, "Item C3" );

    m_clcList.InsertItem(  4,    "Item A4" );
    m_clcList.SetItemText( 4, 1, "Item B4" );
    m_clcList.SetItemText( 4, 2, "Item C4" );
}


The code just calculates the width of the control, then sets the column widths accordingly.  As a bonus, I added some code to show you how to populate the list
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question