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?
jkrConnect With a Mentor Commented:
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.

DanRollinsConnect With a Mentor Commented:
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.
mahesh1402Connect With a Mentor Commented:
>>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"

All Courses

From novice to tech pro — start learning today.