A user can click on row 5 or cursor down to row 5 of a ListView, but how can I set the current row to 5(any number actually) under program control? I have been able to get the current row number by intercepting the LVN_ITEMCHANGED message. I use the data in the columns to populate other fields on my form. When the program starts up, it fills the LV and then needs to select the first row so that the fields and the current row are showing the same data. I am ashamed to admit that I resorted to giving the LV focus and then sending it a down arrow to it to get it to highlight the first row.:mad: Thanking you in advance, Onyx
You need to use LVM_SETITEMSTATE:
.data? LVI LVITEM > .code mov LVI.state,LVIS_SELECTED mov LVI.stateMask,LVIS_SELECTED invoke SendMessage,hList,LVM_SETITEMSTATE,0,ADDR LVI ;0 indicates the first row
That has the appearance of working but.... If the user leaves the listview on the second row (index 1) and I set it, using your example (thanks by the way), to row 5 then row 5 is indeed selected onscreen. But when the user hits the down arrow, row three is selected. It appears that your solution sets the row "selected" but does not the modify the LV's index.
To make the row selected and focused, simply do the following: .data? LVI LVITEM > .code mov LVI.state,LVIS_SELECTED or LVIS_FOCUSED mov LVI.stateMask,LVIS_SELECTED or LVIS_FOCUSED invoke SendMessage,hList,LVM_SETITEMSTATE,0,ADDR LVI