CListCtrl Column Width

Posted on 2006-04-25
Last Modified: 2013-11-20
This is the code I have for creating a ListCtrl in an Active X.  The problem is on the Insert Column, I thought the 3000 is supposed to be the column width.  The column with for the both of these columns look extremely small.  I've tried changing this number and nothing happens?  Any ideas?

      CRect rectCl();

      m_ctrl=new CListCtrl();
      m_ctrl->Create(WS_VISIBLE|LVS_REPORT, rectCl, this, 100);

      m_ctrl->InsertColumn(0, "Tree", 3000);
      m_ctrl->InsertColumn(1, "Grass", 3000);
Question by:cophi
    LVL 86

    Accepted Solution

    You are using the 3rd parameter, which is th eformat, and not the witdth:

    int CListCtrl::InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );

    Better try

         m_ctrl->InsertColumn(0, "Tree", LVCFMT_LEFT, 3000);
         m_ctrl->InsertColumn(1, "Grass", LVCFMT_LEFT, 3000);

    which should fix that. BTW: '3000' is a way too big value, IMHO.

    LVL 49

    Assisted Solution

    As jkr indicated, you need to specify the width as the fourth parameter -- the columns look small because they are being set to some internal default minimum width.

    One other thing... if you use the code as indicated above, you might think that there is an error because just one column will appear!  The width of the control has been set at 500, but each column is 3000.  For testing purposes at least, it will be better to use, e.g.:

         m_ctrl->InsertColumn(0, "Tree",  LVCFMT_LEFT, 300 );  // what's an order of
         m_ctrl->InsertColumn(1, "Grass", LVCFMT_LEFT, 300 ); // magnitude between freinds?

    -- Dan
    LVL 14

    Expert Comment

    Also You can call the seperate function for this.

    m_List.SetColumnWidth( (nColNo , 100);

    //m_List - List control var
    //nColNo - Column no.
    //100 - width of the column. you can replace it by your own number.
    LVL 22

    Assisted Solution

    >>I thought the 3000 is supposed to be the column width.

    what makes you to calculate width 3000 pixels of list control column ??

    e.g if you want to set column width of list control with  string  "Tree"

    int ColumnWidthPadding = 10; //some padding
    m_ctrl->InsertColumn(0, "Tree", LVCFMT_LEFT, m_ctrlList.GetStringWidth("Tree")+ColumnWidthPadding); //set column width of "Tree"


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    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.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now