Author Topic: Select a single cell in a listview  (Read 131 times)

jj2007

  • Member
  • *****
  • Posts: 7884
  • Assembler is fun ;-)
    • MasmBasic
Select a single cell in a listview
« on: December 27, 2017, 05:33:37 AM »
Question: 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 :(

fearless

  • Member
  • ***
  • Posts: 294
    • LetTheLightIn
Re: Select a single cell in a listview
« Reply #1 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:
Code: [Select]
    .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
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI, Samsung 256GB + 1TB SSD, WD Black 2TB x2 + 4TB HDD, Asus 27" LCD

www.LetTheLight.in  My Github

aw27

  • Member
  • ****
  • Posts: 961
  • Let's Make ASM Great Again!
Re: Select a single cell in a listview
« Reply #2 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)

Code: [Select]
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

jj2007

  • Member
  • *****
  • Posts: 7884
  • Assembler is fun ;-)
    • MasmBasic
Re: Select a single cell in a listview
« Reply #3 on: December 27, 2017, 09:35:57 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_

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
Quote
ListView Colors

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