How to get which row selected in a list view control report mode?

Started by dicky96, August 22, 2006, 10:02:41 PM

Previous topic - Next topic

dicky96

Had a good look around in MSDN and done a search on here and can't seem to find an answer to this one.

I finally got a list view control working.  When you click in a cell, the whole row highlights - this seems to be default window processiing.

What I need to know in my program is which row is highlighted so when the user clicks an "edit" button I know which row of data to present for editing (in a separate dialog).  There is a LVM_GETCOLUMN message, but why no LVM_GETROW??

dicky

drizz

LVM_GETNEXTITEM :wink

invoke SendMessage,hLv,LVM_GETNEXTITEM,-1,LVNI_SELECTED
The truth cannot be learned ... it can only be recognized.

dicky96

Yep That Works  :8)  Thanks

Another question if that's ok.....

When it comes to reading the listview item text I noticed according to MSDN it says that I can also use macros such as ListView_GetItemText rather than filling in an LVITEM structure and sending LVM_GETITEMTEXT messages - but that does not seem to work for me (like masm via radasm does not understand the function call) so I had to use the message method and eventually figured out the correct lvi.mask toget it working.

But the macro seemed easier (if it worked), so how exactly do I use these sort of macros I find on MSDN??

PBrennick

invoke  ListView_GetItemText, hwnd, iItem, iSubItem, pszText, TextMax

where:
hwnd = Handle to the list view control.
iItem = Index of the list view item.
iSubItem = Index of the subitem, or zero to retrieve the item label.
pszText = Pointer to the buffer that receives the item or subitem text.
TextMax = Size of the buffer, in bytes.

That is all there is to know.  Nothing is returned in eax unlike using LVM_GETITEMTEXT which returns the length of the retrieved string.  You would get this from TextMax, specifically.

Perhaps you can explain what your problem was?  Were you expecting a value in EAX?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

drizz

dicky96,there are "some" macros by Four-F that do the same thing as those C/C++ macros.
see attach.

Paul, those are not exported procedures but C/C++ macros.



[attachment deleted by admin]
The truth cannot be learned ... it can only be recognized.

w0lfshad3

Perhaps i'm a bit late but perhaps this would help:

Charles Petzold, Programming Windows Fifth Edition

QuoteA Hypothetical Example
Here's an example. Suppose your program needs to display several columns of alphabetically sorted files. Normally, you would use the list view control because it does all the hit-testing work for you. But let's suppose you can't use it for some reason. You need to do it yourself. Let's assume that the filenames are stored in a sorted array of pointers to character strings named szFileNames.

Let's also assume that the file list starts at the top of the client area, which is cxClient pixels wide and cyClient pixels high. The columns are cxColWidth pixels wide; the characters are cyChar pixels high. The number of files you can fit in each column is


iNumInCol = cyClient / cyChar ;

When your program receives a mouse click message, you can obtain the cxMouse and cyMouse coordinates from lParam. You then calculate which column of filenames the user is pointing at by using this formula:


iColumn = cxMouse / cxColWidth ;

The position of the filename in relation to the top of the column is


iFromTop = cyMouse / cyChar ;

Now you can calculate an index to the szFileNames array.


iIndex = iColumn * iNumInCol + iFromTop ;

If iIndex exceeds the number of files in the array, the user is clicking on a blank area of the display.

In many cases, hit-testing is more complex than this example suggests. When you display a graphical image containing many parts, you must determine the coordinates for each item you display. In hit-testing calculations, you must go backward from the coordinates to the object. This can become quite messy in a word-processing program that uses variable font sizes, because you must work backward to find the character position with the string.


dicky96

@PBrennick
I think it was just a typo error in my program.  Was late last night when i was playing with that stuff.