List Control with Grouped View
-
Has anybody managed to get the grouping working with the list control (as seen in My Computer as it separates your hard drives from your CD ROMs for example)? It feels like I have been banging my head against a brick wall all afternoon trying to get it to work with no joy. I have created a new project with VS 2002 so I assume all the manifest requirements have been met. I then get the list control from the CListView and add a group using the InsertGroup() function. I then insert two items using the InsertItem() function and for each item I set the Group ID to the corresponding group. This is the code I have so far. I would be eternally grateful if someone could point out what I am not doing correctly or have failed to do all together. //Get the listCtrl from the View CListCtrl& ctrl = GetListCtrl(); //View control in icon veiw ctrl.ModifyStyle(0, LVS_ICON); //Enable the Group View so we can group the entries ctrl.EnableGroupView(TRUE); //Add a Column ctrl.InsertColumn(0, "Name"); ctrl.SetColumnWidth(0, 300); //Add the groups to the control LVGROUP* pGroup = new LVGROUP; if(pGroup != NULL) { ZeroMemory(pGroup, sizeof(LVGROUP)); pGroup->cbSize = sizeof(LVGROUP); pGroup->mask = LVGF_HEADER | LVGF_ALIGN | LVGF_STATE | LVGF_GROUPID; pGroup->pszHeader = L"Coordinate Reference Systems"; pGroup->cchHeader = 28; pGroup->stateMask = 0; pGroup->state = LVGS_NORMAL; pGroup->uAlign = LVGA_HEADER_LEFT; pGroup->iGroupId = 0; LRESULT res = ctrl.InsertGroup(0, pGroup); TRACE("Group added"); } //Add a second group LVGROUP* pGroup2 = new LVGROUP; if(pGroup2 != NULL) { ZeroMemory(pGroup2, sizeof(LVGROUP)); pGroup2->cbSize = sizeof(LVGROUP); pGroup2->mask = LVGF_HEADER | LVGF_ALIGN | LVGF_STATE | LVGF_GROUPID; pGroup2->pszHeader = L"Coordinate Reference Systems"; pGroup2->cchHeader = 28; pGroup2->stateMask = 0; pGroup2->state = LVGS_NORMAL; pGroup2->uAlign = LVGA_HEADER_LEFT; pGroup2->iGroupId = 1; LRESULT res = ctrl.InsertGroup(1, pGroup2); TRACE("Group added"); } //Add a couple of items LVITEM* pLVItem = new LVITEM; ZeroMemory(pLVItem, sizeof(LVITEM)); pLVItem->mask = LVIF_GROUPID | LVIF_TEXT; pLVItem->iItem = 0; pLVItem->iGroupId = 0; pLVItem->pszText = _T("Andy"); pLVItem->cchTextMax = 4; ctrl.InsertItem(pLVItem); LVITEM* pLVItem2 = new LVITEM; ZeroMemory(pLVItem2, sizeof(LVITEM)); pLVItem2->mask = LVIF_GROUPID | LVIF_TEXT; pLVItem2->iItem = 1; pLVItem2->iGroupId = 1; pLVItem
-
Has anybody managed to get the grouping working with the list control (as seen in My Computer as it separates your hard drives from your CD ROMs for example)? It feels like I have been banging my head against a brick wall all afternoon trying to get it to work with no joy. I have created a new project with VS 2002 so I assume all the manifest requirements have been met. I then get the list control from the CListView and add a group using the InsertGroup() function. I then insert two items using the InsertItem() function and for each item I set the Group ID to the corresponding group. This is the code I have so far. I would be eternally grateful if someone could point out what I am not doing correctly or have failed to do all together. //Get the listCtrl from the View CListCtrl& ctrl = GetListCtrl(); //View control in icon veiw ctrl.ModifyStyle(0, LVS_ICON); //Enable the Group View so we can group the entries ctrl.EnableGroupView(TRUE); //Add a Column ctrl.InsertColumn(0, "Name"); ctrl.SetColumnWidth(0, 300); //Add the groups to the control LVGROUP* pGroup = new LVGROUP; if(pGroup != NULL) { ZeroMemory(pGroup, sizeof(LVGROUP)); pGroup->cbSize = sizeof(LVGROUP); pGroup->mask = LVGF_HEADER | LVGF_ALIGN | LVGF_STATE | LVGF_GROUPID; pGroup->pszHeader = L"Coordinate Reference Systems"; pGroup->cchHeader = 28; pGroup->stateMask = 0; pGroup->state = LVGS_NORMAL; pGroup->uAlign = LVGA_HEADER_LEFT; pGroup->iGroupId = 0; LRESULT res = ctrl.InsertGroup(0, pGroup); TRACE("Group added"); } //Add a second group LVGROUP* pGroup2 = new LVGROUP; if(pGroup2 != NULL) { ZeroMemory(pGroup2, sizeof(LVGROUP)); pGroup2->cbSize = sizeof(LVGROUP); pGroup2->mask = LVGF_HEADER | LVGF_ALIGN | LVGF_STATE | LVGF_GROUPID; pGroup2->pszHeader = L"Coordinate Reference Systems"; pGroup2->cchHeader = 28; pGroup2->stateMask = 0; pGroup2->state = LVGS_NORMAL; pGroup2->uAlign = LVGA_HEADER_LEFT; pGroup2->iGroupId = 1; LRESULT res = ctrl.InsertGroup(1, pGroup2); TRACE("Group added"); } //Add a couple of items LVITEM* pLVItem = new LVITEM; ZeroMemory(pLVItem, sizeof(LVITEM)); pLVItem->mask = LVIF_GROUPID | LVIF_TEXT; pLVItem->iItem = 0; pLVItem->iGroupId = 0; pLVItem->pszText = _T("Andy"); pLVItem->cchTextMax = 4; ctrl.InsertItem(pLVItem); LVITEM* pLVItem2 = new LVITEM; ZeroMemory(pLVItem2, sizeof(LVITEM)); pLVItem2->mask = LVIF_GROUPID | LVIF_TEXT; pLVItem2->iItem = 1; pLVItem2->iGroupId = 1; pLVItem
You've failed to state the problem. Are you getting compiler or linker errors? Is an assertion firing? Is an exception being thrown? I see very little error checking. Is this intentional, or done for the sake of brevity? Are any of the functions returning "error" status?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
You've failed to state the problem. Are you getting compiler or linker errors? Is an assertion firing? Is an exception being thrown? I see very little error checking. Is this intentional, or done for the sake of brevity? Are any of the functions returning "error" status?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
The problem is that the groups are not being displayed. When the lsit control gets displayed the two Items are present but like I said there are no groups. The code included in my original post is a bit of proof of concept code, ie just to see the groups working. I was convinced that none of the functions were returning error codes, so I have been back and checked just to be sure. None of the functions return an error code, however what doesn't seem right is the fact that bot calls to InsertGroup returns 0 it should return "index of the item that the group was added to". So I would expect the first call to return 0 but the second call I would expect to return 1. Cheers Andy
-
The problem is that the groups are not being displayed. When the lsit control gets displayed the two Items are present but like I said there are no groups. The code included in my original post is a bit of proof of concept code, ie just to see the groups working. I was convinced that none of the functions were returning error codes, so I have been back and checked just to be sure. None of the functions return an error code, however what doesn't seem right is the fact that bot calls to InsertGroup returns 0 it should return "index of the item that the group was added to". So I would expect the first call to return 0 but the second call I would expect to return 1. Cheers Andy
AndyCheetham wrote: So I would expect the first call to return 0 but the second call I would expect to return 1. As grouping is a new thing to VS.Net, I've no experience with it. In your code, you added two groups. You then added one item to each group. My guess is that the items in each group are independent of the other. In other words, if you added five items to the first group, they would be numbered 0-4. If you added five items to the second group, would they be numbered 0-4 or 5-9?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
AndyCheetham wrote: So I would expect the first call to return 0 but the second call I would expect to return 1. As grouping is a new thing to VS.Net, I've no experience with it. In your code, you added two groups. You then added one item to each group. My guess is that the items in each group are independent of the other. In other words, if you added five items to the first group, they would be numbered 0-4. If you added five items to the second group, would they be numbered 0-4 or 5-9?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
Hi David Thanks for your input. Just thought I would let you know that I have solved the problem. You need to include the following line in the rc file! CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "GLook.manifest" where Glook.manifest id replaced with the file name for the manifest file for your application. Unfortunately this is mentioned in the help file that I looked at when I first started looking into the problem. One day I will learn to read instructions more carefully.;):doh: Thanks for your help Andy