Discussion:
? ListCtrl col align won't work when col added later
(too old to reply)
Alec S.
2004-02-17 22:27:22 UTC
Permalink
Hi,

I've got a dialog with a list control. It's associated with a CListCtrl
and I insert a few columns in InitDialog. Everything is fine so far. But
later I add some more columns to the CListCtrl but those always end up
Left-Aligned, and I can't get them to use a different alignment even if I
hard code it in the call to InsertColumn.

What's wrong? How can I fix it?


Thanks a lot.

--
Alec S.
alec @ synetech . cjb . net
Gary Chang
2004-02-18 02:52:02 UTC
Permalink
Hi Alec,

Thanks for posting in the community.

From your post, I understand that you cannot set a different alignment to a
ListCtrl while hard coding it in the call to InsertColumn.

I created a test MFC dialog project according to your description, and used
the following code to test the InsertColumn method, it works OK:
BOOL CPListCtrlDlg::OnInitDialog()
{
...
// TODO: Add extra initialization here
m_lst1.InsertColumn(0, "1st Info",LVCFMT_LEFT, 90);
m_lst1.InsertColumn(1, "2nd Info",LVCFMT_CENTER, 90);
m_lst1.InsertColumn(2, "3rd Info",LVCFMT_RIGHT, 90);
m_lst1.InsertItem(1, "Left, left");
m_lst1.InsertItem(2, "2nd row");
m_lst1.SetItemText(0, 1, "Center..");
m_lst1.SetItemText(0, 2, "Right..");
...
}

void CPListCtrlDlg::OnOK()
{
// TODO: Add extra validation here

m_lst1.InsertColumn(3, "4th Info",LVCFMT_CENTER, 75);
m_lst1.SetItemText(0, 3, "New..");
}

So I think to isolate the problem on your side, would you please to upload
a stand-alone sample project(.zip) to the newsgroup, if not inconvenience?


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Gary Chang
2004-02-20 06:20:41 UTC
Permalink
Hi Alec,

Thanks for posting in the community.

I have received your sample project and can repro the problem.

However, based on my experience, the leftmost column of a ListCtrl is the
main item to a row, which can contains the small icon and label, this
column has alway the Left alignment style, it will ignore the specifying of
the alignment. It is by design to this control.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
J_ B
2004-02-20 09:54:15 UTC
Permalink
Hi, you can do this by setting the column order after inserting the column
(often useful when using drag n drop columns). In your code:

void CtestView::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
m_List.InsertColumn(1, "new col. (r)", LVCFMT_RIGHT, 100);

LVCOLUMN cl;
cl.mask=LVCF_ORDER;
cl.iOrder=0;
m_List.SetColumn(1,&cl);

m_List.InsertItem(0, "abcdef");
m_List.SetItemText(0, 1, "abcdef");
m_List.SetItemText(0, 2, "abcdef");
}

Hope that helps.
Jai
Post by Gary Chang
Hi Alec,
Thanks for posting in the community.
I have received your sample project and can repro the problem.
However, based on my experience, the leftmost column of a ListCtrl is the
main item to a row, which can contains the small icon and label, this
column has alway the Left alignment style, it will ignore the specifying of
the alignment. It is by design to this control.
Thanks!
Best regards,
Gary Chang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Alec Soroudi
2004-02-20 22:02:38 UTC
Permalink
I see. I tried it and it works like a charm.

Thanks to both of you, now I know why it does that, and how to work
around it. Great, now I can continue work on that app.

Thanks again!

--
Alec
***@synetech.cjb.net



Post by J_ B
Hi, you can do this by setting the column order after inserting the column
void CtestView::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
m_List.InsertColumn(1, "new col. (r)", LVCFMT_RIGHT, 100);
LVCOLUMN cl;
cl.mask=LVCF_ORDER;
cl.iOrder=0;
m_List.SetColumn(1,&cl);
m_List.InsertItem(0, "abcdef");
m_List.SetItemText(0, 1, "abcdef");
m_List.SetItemText(0, 2, "abcdef");
}
Hope that helps.
Jai
Post by Gary Chang
Hi Alec,
Thanks for posting in the community.
I have received your sample project and can repro the problem.
However, based on my experience, the leftmost column of a ListCtrl is the
main item to a row, which can contains the small icon and label, this
column has alway the Left alignment style, it will ignore the specifying
of
Post by Gary Chang
the alignment. It is by design to this control.
Thanks!
Best regards,
Gary Chang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Gary Chang
--------------------
Gary Chang
2004-02-20 01:17:03 UTC
Permalink
Hi Alec,

What's the thing going about your program?

However, if the problem still persists, please upload a small sample
project to help me for further troubleshooting.

Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Loading...