| |

VerySource

 Forgot password?
 Register
Search
View: 775|Reply: 5

GetFirstSelectedItemPosition() returns the selected row, why is it always 0?

[Copy link]

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-8 09:00:01
| Show all posts |Read mode
void CStudentManageView::OnClickLISTBaseInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
//When clicking, select a row
::SendMessage(m_listBaseInfo.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);

//Display student achievement information of the selected row
    POSITION pos = m_listBaseInfo.GetFirstSelectedItemPosition();
if(pos == NULL)
{
MessageBox("No Item is Selected");
}
else
{
while (pos)
{
int nItem = m_listBaseInfo.GetNextSelectedItem(pos);
}
}

int a = m_listBaseInfo.GetSelectionMark();
*pResult = 0;
}


No matter which row I click, it returns 0x00000, which is NULL. I don't know what happened? I am a novice, thanks
Reply

Use magic Report

0

Threads

32

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-12-8 12:15:01
| Show all posts
Try adding a sentence to the first line of this function:
void CStudentManageView::OnClickLISTBaseInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
  m_listBaseInfo.SetFocus(); // Activate the list control
  // ...
Reply

Use magic Report

1

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-12-8 12:30:02
| Show all posts
Still not working
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-12-8 13:45:01
| Show all posts
Maybe you should change the notification response message instead of responding to LVN_CLICK, but to respond to the LVN_ITEMCHANGED notification. In addition, pNMHDR can be cast to a type related to the ListView control. There may be a member iItem. If it is not -1, it should be I can't remember the current line being clicked.
Reply

Use magic Report

0

Threads

32

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-12-8 14:00:01
| Show all posts
Remove the following sentence
::SendMessage(m_listBaseInfo.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
This work should set the style of m_listBaseInfo to LVS_EX_FULLROWSELECT at the time of initialization, so that when you click, an entire row will be automatically selected, at this time GetFirstSelectedItemPosition(); has a value
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-8 18:00:01
| Show all posts
Original poster, I also encountered this problem a few days ago. Later, I realized that position and id can be used for direct reference. When you enter OnClickLISTBaseInfo, position has become the value you clicked. Using the SelectedItemPosition() method will erase the position value, it’s that simple
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list