Solved

ListView

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

688 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