How to select CListCtrl item question
2008-09-19 19:39
441 查看
http://www.codeguru.com/forum/archive/index.php/t-221250.html
Ok, I searched the archives and have asked this question before with no response so I am asking it again. I am still trying to select an item in the CListCtrl. Current I have the following code:
CListCtrl = *m_pPlist = (CListCtrl *)GetDlgItem(IDC_LISTCTRL);
POSITION pos = m_pPList->GetFirstSelectedItemPosition();
if(pos == NULL)
AfxMessageBox("No Items Listed");
return;
...
If there are 5 listed items and none is selected pos is always NULL. If I select one of the items with the mouse then it works. I want just want to click on a button, which I have created, to begin processing the items in the list. I need to automatically go to the first item on the list and then select it.
Can't find out how to set the selected item to the first postion automatically without having to use the mouse to select the item.
Any help will be appreciated.
Mike@spb
John E
December 3rd, 2002, 11:30 AM
I've never actually done this but from the documentation it looks as though CListCtrl::GetItemState() and CListCtrl::SetItemState() are intended for this purpose. They allow you to set an item's state (for example to be LVIS_SELECTED) by knowing it's index.
You can also change an item's position by using CListCtrl::GetItemPosition() and CListCtrl::SetItemPosition() - again by using the item's index.
Elrond
December 3rd, 2002, 11:38 AM
John E is right.
To select an item you must use:
m_ListCtrl.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
To unselect an item you must use:
m_ListCtrl.SetItemState(i, 0, LVIS_SELECTED);
The function you were using (GetFirstSelectedItemPosition) is made to GET the selected items, not to SET them.
In your case, after clicking an item, this function would only return you the index of this item. No way you can process all the items that way.
Ok, I searched the archives and have asked this question before with no response so I am asking it again. I am still trying to select an item in the CListCtrl. Current I have the following code:
CListCtrl = *m_pPlist = (CListCtrl *)GetDlgItem(IDC_LISTCTRL);
POSITION pos = m_pPList->GetFirstSelectedItemPosition();
if(pos == NULL)
AfxMessageBox("No Items Listed");
return;
...
If there are 5 listed items and none is selected pos is always NULL. If I select one of the items with the mouse then it works. I want just want to click on a button, which I have created, to begin processing the items in the list. I need to automatically go to the first item on the list and then select it.
Can't find out how to set the selected item to the first postion automatically without having to use the mouse to select the item.
Any help will be appreciated.
Mike@spb
John E
December 3rd, 2002, 11:30 AM
I've never actually done this but from the documentation it looks as though CListCtrl::GetItemState() and CListCtrl::SetItemState() are intended for this purpose. They allow you to set an item's state (for example to be LVIS_SELECTED) by knowing it's index.
You can also change an item's position by using CListCtrl::GetItemPosition() and CListCtrl::SetItemPosition() - again by using the item's index.
Elrond
December 3rd, 2002, 11:38 AM
John E is right.
To select an item you must use:
m_ListCtrl.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
To unselect an item you must use:
m_ListCtrl.SetItemState(i, 0, LVIS_SELECTED);
The function you were using (GetFirstSelectedItemPosition) is made to GET the selected items, not to SET them.
In your case, after clicking an item, this function would only return you the index of this item. No way you can process all the items that way.
相关文章推荐
- How to get CListCtrl clicked item information !!
- illustrates how to perform a SELECT statement using ADO.NET
- HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item
- How to select different app.config for several build configurations
- How to access selected rows in an af:selectManyChoice component
- Core Data - How to Do a SELECT DISTINCT
- How to select word spell checking language
- How to select a CRAN mirror in R & use repos parameter(2)
- how to select checkbox on cli environment?
- How to analysis your question?
- HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item
- How to use 'SetItemData()' and 'GetItemData()'?
- Item 43: Know how to access names in templatized base classes(Effective C++)
- How to set up OpenERP for various timezone kindly follow the following steps to select timezone in OpenERP
- How to modify non-customizable entity in MS Dynamics CRM 4.0 (Add Product price column to Price List Item view)
- How to get the value of one specified item
- *****How to access a repositoryItemButtonEdit value from a FileDlg
- how to enable eclipse generate select statement 如何在eclipse里面写sql DDL语句
- HOW to Use QP_PREQ_PUB.PRICE_REQUEST API to Price an Item
- Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how man