The MASM Forum

General => The Campus => Topic started by: jj2007 on December 27, 2017, 05:33:37 AM

Title: Select a single cell in a listview
Post by: jj2007 on December 27, 2017, 05:33:37 AM
Question: (https://social.msdn.microsoft.com/Forums/windows/en-US/b7368cb7-80b5-45ee-af71-e757cfda0fde/select-a-single-cell-in-listview?forum=winforms) I am using the listview with C# in VS.NET 2005. I would like to select a single cell (not just cells in the first column)

Answer: To my knowledge the ListView control does not support this. You need to use a DataGrid or DataGridView control (mark, DataGridView Program Manager, Micros**t)

Does the bloody listview really not support a single cell selection?? DataGridView is utterly clumsy and needs gigabytes of download :(
Title: Re: Select a single cell in a listview
Post by: fearless on December 27, 2017, 07:00:20 AM
No not natively, you can use LVM_SUBITEMHITTEST to get the item and subitem clicked and then create an editbox at the location of the cell to emulate the cell being selected. I did some playing round with listbox and dropdownlistboxes in listviews a while back: http://www.masmforum.com/board/index.php?topic=17551.0
think it also included an editbox in the example (cant remember)

using something like:
    .elseif eax==WM_NOTIFY
        mov ecx, lParam
        mov eax, (NMHDR PTR [ecx]).idFrom
        .IF eax == IDC_LV
           
            mov eax, (NMHDR PTR [ecx]).code
            mov ebx, (NMHDR PTR [ecx]).hwndFrom
            mov hwndLV, ebx
            .IF eax == NM_CLICK
               
                invoke GetCursorPos, addr lvhi.pt
                invoke ScreenToClient, hwndLV, addr lvhi.pt
                invoke SendMessage,hwndLV,LVM_SUBITEMHITTEST,0, Addr lvhi ; returns the column and item that was clicked in lvhi
               
                Invoke SendMessage, hwndLV, LVM_GETITEMCOUNT, 0, 0
                .IF (eax > lvhi.iItem)
                    .IF (lvhi.iSubItem == 0) ; superpower column

                    .ELSEIF (lvhi.iSubItem == 1) ; student name
                        Invoke ListViewEditBoxMode, hwndLV, IDC_EDIT, lvhi.iItem, lvhi.iSubItem ;

                       
                    .ELSEIF (lvhi.iSubItem == 2) ; age
                        Invoke ListViewDropDownListMode, hwndLV, IDC_CBO_DDL_AGE, lvhi.iItem, lvhi.iSubItem
                   
                    .ELSEIF (lvhi.iSubItem == 3) ; sex


                    .ELSEIF (lvhi.iSubItem == 4) ; classroom
                                 

                    .ELSEIF (lvhi.iSubItem == 5) ; teacher
                       

                    .ELSEIF (lvhi.iSubItem == 6) ; progress

                    .ENDIF       
                .ENDIF


Been a while since i looked at it but might point you in the right direction
Title: Re: Select a single cell in a listview
Post by: aw27 on December 27, 2017, 07:17:47 AM
You can do as explained in this article:
https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win-API

ListView_SetItemState is actually a macro which translates more or less to this pseudocode procedure (untested)


proc ListView_SetItemState hwndListView: HWND, item:dword, _data:WPARAM, _mask:LPARAM
LOCAL lvi : LVITEM
mov lvi.statemask,_mask
mov lvi.state, _data
invoke Sendmessage, hwndListView, 102bh, item, addr lv
ret
ListView_SetItemState endp
Title: Re: Select a single cell in a listview
Post by: jj2007 on December 27, 2017, 09:35:57 AM
Quote from: fearless on December 27, 2017, 07:00:20 AM
No not natively, you can use LVM_SUBITEMHITTEST to get the item and subitem clicked and then create an editbox at the location of the cell to emulate the cell being selected.

Yes, that was my plan, too. Thanks for pointing me to the right LVM_

Quote from: aw27 on December 27, 2017, 07:17:47 AM
You can do as explained in this article:
https://www.codeproject.com/Articles/2890/Using-ListView-control-under-Win-API

Exactly what I was looking for :t
QuoteListView Colors

You won't believe how much time I took to dig this up to actually work!
:biggrin: