kann ich in einer Multiselect-Listbox das Item feststellen auf das doppelgeklickt wurde?
Mit :getItem() erhalte ich natürlich ein Array mit allen markierten Elementen.
Code: Alles auswählen
oLbox:ItemSelected:={|| neu_name(oLbox:getdata([1])) }
Moderator: Moderatoren
Code: Alles auswählen
oLbox:ItemSelected:={|| neu_name(oLbox:getdata([1])) }
das ist bei Xbase++ "so" vorgesehen... aber du muss ja nicht o:ItemSelected benutzen !peternmb hat geschrieben:kann ich in einer Multiselect-Listbox das Item feststellen auf das doppelgeklickt wurde?
Code: Alles auswählen
#include "Appevent.ch"
#include "Xbp.ch"
#include "Gra.ch"
#include "Common.ch"
#include "Directry.ch"
#include "ot4xb.ch"
#define LB_GETCURSEL 0x0188
#define LB_GETTEXT 0x0189
#define LB_GETTEXTLEN 0x018A
#define PicHeigh 240
#define Titlebar 50
PROCEDURE appsys ; return
PROCEDURE Main(cPath)
LOCAL nEvent, oXbp, mp1, mp2
LOCAL oDlg
LOCAL oListBox
LOCAL oDa
LOCAL aSize
LOCAL i, iMax
LOCAL aDir
LOCAL nVersion := 0
LOCAL aMark := {}
LOCAL aSele := {}
LOCAL zPath := LEFT(AppName(.t.),LEN(AppName(.t.)) - LEN(AppName(.f.)))
LOCAL aPP := { { XBP_PP_COMPOUNDNAME, "10.Arial" },;
{ XBP_PP_BGCLR , XBPSYSCLR_WINDOW },;
{ XBP_PP_FGCLR , XBPSYSCLR_WINDOWTEXT },;
{ XBP_PP_HILITE_FGCLR, XBPSYSCLR_HILITEFOREGROUND },;
{ XBP_PP_HILITE_BGCLR, XBPSYSCLR_HILITEBACKGROUND } }
DEFAULT cPath TO zPath
SET DATE GERMAN
SET CENTURY ON
aDir := Directory(cPath+"*.*")
oDlg := XbpDialog():New(AppDesktop(),,{0,0}, {533,PicHeigh+Titlebar},,.F.)
oDlg:taskList := .T.
oDlg:title := "Picture ListBox"
oDlg:close := {|p1,p2,oo| PostAppEvent(xbeP_Quit,,,oo) }
oDlg:drawingArea:resize := {| aOldSize, aNewSize, oSelf | MyResize(aOldSize,aNewSize,oSelf,oListBox) }
oDlg:Create()
oDlg:drawingArea:ClipChildren := .T.
CenterControl(oDlg)
oDa := oDlg:drawingArea
aSize := oDa:Currentsize()
aSize := {oDa:Currentsize()[1]-20,PicHeigh}
oListBox := XbpListbox():new(oDa ,,{10,10},aSize,aPP)
//
// does not work with ownerdraw
//
oListBox:multiColumn := .T.
oListBox:markMode := XBPLISTBOX_MM_MULTIPLE
oListBox:itemMarked := {|mp1, mp2, oSelf| aMark := oSelf:getdata() }
* oListBox:ItemSelected := {|mp1, mp2, oSelf| aSele := oSelf:getdata() , ShowWhat(oSelf,aSele,aMark) }
oListBox:lbDblClick := {| aPos, uNIL, oSelf| aSele := oSelf:getdata() , ShowWhat(oSelf,aSele,aMark,aPos) }
oListBox:create()
iMax := LEN( aDir )
FOR i := 1 TO iMax
oListBox:AddItem( aDir[i][F_NAME]+CHR(9)+STR(aDir[i][F_SIZE])+CHR(9)+DTOC(aDir[i][F_DATE]) )
NEXT
oDlg:Show()
SetAppWindow( oDlg )
SetAppFocus( oListBox )
oListBox:setdata({1}) // Focus to 1st Item
nEvent := xbe_None
WHILE nEvent != xbeP_Close
nEvent := AppEvent ( @mp1, @mp2, @oXbp )
oXbp:HandleEvent ( nEvent, mp1, mp2 )
IF nEvent == xbeP_Quit
QUIT // AppQuit()
ENDIF
ENDDO
oListBox:destroy()
oDlg:destroy()
RETURN
FUNCTION LB_GetCursorSelect(hLbox)
/******************************************************************************
Returns the index of the currently selected item.
wParam
Not used; must be zero.
lParam
Not used; must be zero.
Return Value
In a single-selection list box, the return value is the zero-based index
of the currently selected item. If there is no selection, the return value
is LB_ERR.
******************************************************************************/
RETURN @User32:SendMessageA(hLbox,LB_GETCURSEL,0,0)
FUNCTION LB_GetText(nIndex,hLbox)
/******************************************************************************
Retrieves the string associated with a specified item and the length of the string.
wParam
The zero-based index of the string to retrieve.
lParam
A pointer to the buffer that will receive the string
it is type LPTSTR which is subsequently cast to an LPARAM.
The buffer must have sufficient space for the string and a terminating
null character.
An LB_GETTEXTLEN message can be sent before the LB_GETTEXT message to
retrieve the length, in TCHARs, of the string.
Return Value
The return value is the number of items placed in the buffer.
If the list box is a single-selection list box, the return value is LB_ERR.
******************************************************************************/
LOCAL cString := ""
LOCAL nLen := 256
LOCAL nErr := 0
nLen := LB_GetTextLen(nIndex, hLbox)
IF nLen = 0
nLen := 80
ENDIF
cString := SPACE(nLen)
nErr := @User32:SendMessageA(hLbox,LB_GETTEXT,nIndex,@cString)
// if nErr <> 0 ...
RETURN cString
FUNCTION LB_GetTextLen(nIndex,hLbox)
/******************************************************************************
Returns the length, in characters, of the string associated with a specified item.
wParam
The zero-based index of the string.
lParam
This parameter is not used.
Return Value
The return value is the length of the string, in TCHARs, excluding the
terminating null character. Under certain conditions, this value may
actually be greater than the length of the text.
If the wParam parameter does not specify a valid index, the return value
is LB_ERR.
******************************************************************************/
LOCAL nRet := 0
nRet := @User32:SendMessageA(hLbox,LB_GETTEXTLEN,nIndex,0)
RETURN nRet
PROCEDURE ShowWhat(oSelf,aSele,aMark,aPos)
LOCAL hLbox := oSelf:getHWND()
LOCAL nIndex := LB_GetCursorSelect(hLbox)
LOCAL cText := LB_GetText(nIndex,hLbox)
LOCAL cMsg := ""
LOCAL i,iMax
iMax := LEN(aMark)
IF iMax > 0
FOR i := 1 TO iMax
cMsg += oSelf:getItem(aMark[i])+CHR(13)+CHR(10)
NEXT
ENDIF
Msgbox(cMsg,cText)
RETURN
naja ... es sind nur 2 Methoden die ich aus meinem "native" Control dafür benutzt habe.peternmb hat geschrieben:Ich hätte allerdings nicht erwartet, dass das so aufwändig ist
Code: Alles auswählen
LOCAL nIndex := LB_GetCursorSelect(hLbox)
LOCAL cText := LB_GetText(nIndex,hLbox)
Code: Alles auswählen
#xTranslate XbpListbox => MyListBox