problem with Two LisViews using LVM_GETITEMSTATE

  • Thread starter Thread starter Richard.G
  • Start date Start date
R

Richard.G

Guest
Hi all,

I am developing in Native C++ in a Win32 API environment using Visual Studio 2008. I have two ListViews which are both on the screen and enabled at the same time. My problem is I cannot determine which ListView has been selected when the user presses the Enter (OK) key.


Excerpts of code as follows:

Settings of LVITEM

LvItem.mask = LVIF_TEXT | LVIF_STATE;

LvItem.iItem = 0;

LvItem.iSubItem = 0;

LvItem.state = LVIS_FOCUSED | LVIS_SELECTED;

LvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;

LvItem.pszText = pszText;

LvItem.cchTextMax = MEDIUM; // 50




int iIndex_Group = -1;

int iIndex_Details = -1;

int iGroup_Count = SendMessage(GetDlgItem(hWnd, IDLV_GROUP), LVM_GETITEMCOUNT, 0, 0);

int iDetails_Count = SendMessage(GetDlgItem(hWnd, IDLV_DETAILS), LVM_GETITEMCOUNT, 0, 0);


for(int iCount = 0; iCount <= iGroup_Count; iCount++)

{

if(SendMessage(GetDlgItem(hWnd, IDLV_GROUP), LVM_GETITEMSTATE, iCount, (LPARAM) LVIS_FOCUSED | LVIS_SELECTED))

{

iIndex_Group = iCount;

break;

}

}

for(int iCount = 0; iCount <= iDetails_Count; iCount++)

{

if(SendMessage(GetDlgItem(hWnd, IDLV_DETAILS), LVM_GETITEMSTATE, iCount, (LPARAM) LVIS_FOCUSED | LVIS_SELECTED))

{

iIndex_Details = iCount;

break;

}

}


If the cursor is on the first item of IDLV_GROUP, the iIndex_Group is set correctly, but then it also sets iIndex_Details to 0 as well, which shouldn’t be as .the cursor is still on IDLV_GROUP.


Conversely, if I TAB to IDLV_DETAILS, then it sets iIndex_Group to 0. This should not be the case as the cursor is on IDLV_DETAILS.


I have tried a number of different ways each time the results are the same, including experimenting with different LvItem values. I have also done extensive research on the Web, but cannot find anything that has been helpfull.


Any suggestions, comments etc would be appreciated.


Regards,

Richard

Continue reading...
 
Back
Top