Listview get cell info

Started by Haakon Birkeland, October 07, 2005, 12:54:01 PM

Previous topic - Next topic

Haakon Birkeland

I am trying to convert some code I had from EZGUI but running in some trouble. I want to make a list view to look like a grid.
When I double click on a cell I would like to retreive the rect dimension of the cell the create a textbox of the same size to cover it.
My problem now seem to be how do I get the rect size when I know the row and the column of the listview cell?
thanx
bert
Haakon 8o)

Anonymous

You can use:

Local rectSub As Rect
ListView_GetSubItemRect(HWND_FORM1_LISTVIEW1, lLvItem, lLvSubItem, %LVIR_LABEL, VarPtr(rectSub))  

The Function 'ListView_GetSubItemRect' is a part of COMMCTRL.INC


'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CUSTOM (hWndForm As Dword, wMsg As Long, wParam As Dword, lParam As Long) As Long
   Local pNmLvw     As NM_LISTVIEW Ptr
Local lLvItem     As Long
   Local lLvSubItem As Long
  Local rectSub As Rect  
  Local hFont As Dword                      
'--------------------------------

  Select Case wMsg
   Case %WM_NOTIFY
       Select Case LoWrd(wParam)
           Case IDC_FORM1_LISTVIEW1
               pNmLvw = lParam
               If @pNmLvw.hdr.code = %NM_DBLCLK And (@pNmLvw.iItem > -1) Then 'doppelklick in listview
                   lLvItem     = @pNmLvw.iItem
                   lLvSubItem  = @pNmLvw.iSubItem

                   'welches Listvieitem wurde gewählt
                   Select Case lLvSubItem
                       Case 0
               MsgBox "Column 0 locked"
        Case 1
               GoSub EditZelle
Case 2
              MsgBox "Column 2 locked"
    End Select
End If
  End Select
End Select


Exit Function
EditZelle:

'speichern der Zelle
lEditRow = lLvItem
lEditCol = lLvSubItem

   'ist nur eine Zelle selektiert?
   If IsTrue(ListView_GetItemState(HWND_FORM1_LISTVIEW1, lEditRow, %LVIS_SELECTED)) Then
                   
  'ermitteln der Label des Subitem
ListView_GetSubItemRect(HWND_FORM1_LISTVIEW1, lEditRow, lEditCol, %LVIR_LABEL, VarPtr(rectSub))              
           
       'prüfen ob bereits ein hEdit besteht
       If IsTrue(hEdit) Then DestroyWindow(hEdit): hEdit = %Null      
                   
      ' Create the Edit1 edit control
      hEdit = CreateWindowEx( %WS_EX_LEFT, _                                    ' extended styles
                                "Edit", _                                            ' class name
                                "", _                                                ' caption
                                %WS_CHILD Or %WS_VISIBLE Or %ES_LEFT Or %ES_AUTOHSCROLL Or %ES_NOHIDESEL , _         ' class styles
                                rectSub.nLeft + 6, rectSub.nTop + 6, _               ' left, top
                                rectSub.nRight - rectSub.nLeft, rectSub.nBottom - rectSub.nTop, _   ' width, height
                                hWndForm, 9999, _                        ' handle of parent, control ID
                                GetModuleHandle(ByVal %Null), ByVal %Null)           ' handle of instance, creation parameters
                                                                                                                                                           
'setze Font für EditControl
hFont = GetStockObject(%DEFAULT_GUI_FONT)
      SendMessage hEdit, %WM_SETFONT, hFont, %TRUE

                 
       ShowWindow(hEdit, %SW_SHOW)  
       UpdateWindow(hEdit)    
SetFocus(hEdit)

      'Text aus Listview Zelle in EditControl
      strTextZelle = FF_ListView_GetItemText (HWND_FORM1_LISTVIEW1, lEditRow, lEditCol)
      SendMessage hEdit, %WM_SETTEXT, %FALSE, VarPtr(strTextZelle)  
      SendMessage hEdit, %EM_SETSEL, Len(strTextZelle), Len(strTextZelle)    
 
End If
Return

End Function



Rudolf Fürstauer

Haakon Birkeland

Thank you for the code. Ireally appreciate

Bert
Haakon 8o)