?
Solved

ListView

Posted on 2001-07-29
1
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 49

Accepted Solution

by:
DanRollins earned 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

800 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