Solved

ListView

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now