CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: CListCtrl

Threaded View

  1. #5
    Join Date
    Sep 2002
    Posts
    924
    Here is quick example I tried:
    Dialog app with CListCtrl (with Always Show Selection = TRUE, and View set to list). CListCtrl member variable added (m_List)
    In initdialog under the todo comments I added following:
    Code:
    	// TODO: Add extra initialization here
    	m_List.SetFocus();
    	CString sLabel;
    	// add 10 items to list
    	for(int i = 0;i < 9; i++)
    	{
    		sLabel.Format("Item%d", i);
    		m_List.InsertItem(i, sLabel);
    	}
    	// select 1st 5 items
    	for(int i = 0;i < 5; i++)
    		m_List.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED );
    	// set focus to first item
    	m_List.SetItemState(0, LVIS_FOCUSED , LVIS_FOCUSED  );
    	
    	// return false because I set focus to a control
    	return false;  // return TRUE  unless you set the focus to a control
    When running the program the 1st 5 items are selected and the 1st item has focus, so it should work for you.
    Last edited by RussG1; February 24th, 2004 at 12:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured