Vertical Scrollbar in CListCtrl

拈花ヽ惹草 提交于 2019-12-02 10:08:02

问题


I'm using a CListCtrl in Icon view, but it scrolls horizontally:

1 3 5 7 -->
2 4 6 8 -->

I'd rather it scroll horizontally:

1 2
3 4
5 6
| |
V V

Is there a way to do this?


回答1:


Change the Alignment style in designer from Left to Top.




回答2:


I seem to have resolved the issue by using a 'Report' view. Through the VS Designer this means changing the 'View' style to Report, resulting the control given the LVS_REPORT attribute in the .RC file. Note that this is equivalent to calling CListCtrl::SetView(LV_VIEW_DETAILS) in code. This isn't sufficient however. It is also necessary to create a column if you don't already have one with a couple lines of code:

m_lstScenarios.InsertColumn(0, L"NO HEADER");
m_lstScenarios.SetColumnWidth(k_nListColScenario, LVSCW_AUTOSIZE);

If you don't want the column header, set the LVS_NOCOLUMNHEADER in the Designer through the 'No Column Header' style.




回答3:


On the Visual Studio dialog editor, make sure you have a "List Control," not a "List Box."

On the Visual Studio dialog editor's property list, set "No Column Header" to True and "View" to Report. (Setting "Alignment" to Left has no effect in Report mode.)

In OnInitDialog(), do the following (after calling your superclass's OnInitDialog()):

  CListCtrl* plistError = (CListCtrl*) GetDlgItem( IDC_ERROR );
  plistError->InsertColumn( 0, "" );
  plistError->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

In fact, that seems to give a maximum autosize of the initial width the control is created with. Strings are displayed truncated with an ellipsis at that point. Widening the window does not help.

To correct that, add a method OnSize() to your CDialog subclass that again reminds the list that it's wider. (This assumes that widening the window is what would let the CListCtrl display more text. If you have some other means, such as a button, try this SetColumnWidth() call where you're doing that.)

 WinProgress::OnSize() {
    CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
    plist->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

You may then add new rows to the bottom of the list with code such as:

  CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
  int iCount = plist->GetItemCount();

  plist->InsertItem( iCount, "Next Item" );

Items too wide for the list will show ellipses at first. When you resize the window however slightly, then the list items wide to full size and a horizontal scrollbar appears if necessary. It's not quite 10/10 as far as look and feel are concerned but even experienced GUI programmers probably won't notice.




回答4:


In list control,to display content with image in single column with vertical scrollbar .add following code, In PreCreateWindow function,add following line cs.style |= (LVS_REPORT|LVS_NOCOLUMNHEADER); and in OnIntialUpdate function add following line, fileList.InsertColumn(0," ",LVCFMT_LEFT|LVCFMT_IMAGE,120,-1); ShowScrollBar(SB_VERT,1); after this,whereever you want to insert data in list you can but take care that you set imagelist and then insert data using insertitem eg: fileList,insertitem(0,"India",1); where 1-> is index of image in imagelist.



来源:https://stackoverflow.com/questions/1806669/vertical-scrollbar-in-clistctrl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!