CListCtrl Column Width

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);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
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.
mahesh1402IT ProfessionalCommented:
>>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"

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.