Solved

ListView

Posted on 2001-07-29
1
181 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 122
Expand LInux Boot partition remotly 3 90
iSeries FTP Exit Program 8 136
Thin secure Windows 10 5 97
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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