CBS_DROPDOWN select all empty text

CBS_DROPDOWN select all empty text

Postby AntoninoP » Wed Dec 11, 2019 4:09 pm

Hello,
I did this simple test:
Code: Select all  Expand view  RUN
#include <fivewin.ch>

proc main()
   LOCAL oWnd, oCombo, cValue// := Space(100)
   DEFINE WINDOW oWnd
   @ 1,1 COMBOBOX oCombo VAR cValue SIZE 200,200 STYLE CBS_DROPDOWN
   //oCombo:oGet:SetSel() //this does nothing
   ACTIVATE WINDOW oWnd


My problem is that when the application starts, the text inside the combobox is all selected:
Image

I see there is no way to avoid the TGet creation on CBS_DROPDOWN, personally I would prefer the TEdit control
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: CBS_DROPDOWN select all empty text

Postby Jimmy » Thu Dec 12, 2019 3:29 am

hi,
AntoninoP wrote:My problem is that when the application starts, the text inside the combobox is all selected:

i see ... empty :idea:

i'm still a FiveWin Newbie so i not know Syntax.
under Xbase++ i "set" most pre-select 1st Element from DropDown List into EDIT Part of ComboBox
Code: Select all  Expand view  RUN
  oCombo:setData( {1} )
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CBS_DROPDOWN select all empty text

Postby AntoninoP » Thu Dec 12, 2019 5:37 am

Jimmy wrote:hi,
AntoninoP wrote:My problem is that when the application starts, the text inside the combobox is all selected:

i see ... empty


my problem is the blue rectangle...

with
Code: Select all  Expand view  RUN
ACTIVATE WINDOW oWnd ON INIT (oCombo:oGet:SetSel())

I obtain a semi-acceptable result
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: CBS_DROPDOWN select all empty text

Postby Jimmy » Thu Dec 12, 2019 6:25 am

AntoninoP wrote:my problem is the blue rectangle...

sorry i don't understand what your Problem with Frame is :?:
do you want "no Frame" or "small Frame with long Text" or other Color of Frame ...

AntoninoP wrote:with
Code: Select all  Expand view  RUN
ACTIVATE WINDOW oWnd ON INIT (oCombo:oGet:SetSel())

I obtain a semi-acceptable result

ok so it is not empty any more a 1st ist select only, or :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CBS_DROPDOWN select all empty text

Postby AntoninoP » Thu Dec 12, 2019 7:29 am

Here my final code...

Code: Select all  Expand view  RUN
#include <fivewin.ch>
#include "Constant.ch"

#xcommand @ <nRow>, <nCol> MYCOMBOBOX [ <oCbx> VAR ] <cVar> ;
             [ <it: PROMPTS, ITEMS> <aItems> ] ;
             [ SIZE <nWidth>, <nHeight> ] ;
             [ <dlg:OF,WINDOW,DIALOG> <oWnd> ] ;
             [ <help:HELPID, HELP ID> <nHelpId> ] ;
             [ ON CHANGE <uChange> ] ;
             [ VALID <uValid> ] ;
             [ <color: COLOR,COLORS> <nClrText> [,<nClrBack>] ] ;
             [ <pixel: PIXEL> ] ;
             [ FONT <oFont> ] ;
             [ <update: UPDATE> ] ;
             [ MESSAGE <cMsg> ] ;
             [ WHEN <uWhen> ] ;
             [ <design: DESIGN> ] ;
             [ BITMAPS <acBitmaps> ] ;
             [ ON DRAWITEM <uBmpSelect> ] ;
             [ STYLE <nStyle> ] ;
             [ <pict: PICT, PICTURE> <cPicture> ];
             [ ON EDIT CHANGE <uEChange> ] ;
             [ HEIGHTGET <nHGet> ] ;
             [ SELHEIGHT <nSelHt> ] ;
             [ ITEMHEIGHT <nItmHt> ] ;
             [ <lw: LISTWIDTH, DROPWIDTH> <nDropW> ] ;
             [ DIRECTORY <cDir> [ATTRIB <attr>] [SAYDIR <oSayDir> ] ] ;
       => ;
          [ <oCbx> := ] MyComboBox():New( <nRow>, <nCol>, bSETGET(<cVar>),;
             <aItems>, <nWidth>, <nHeight>, <oWnd>, <nHelpId>,;
             [{|Self|<uChange>}], <{uValid}>, <nClrText>, <nClrBack>,;
             <.pixel.>, <oFont>, <cMsg>, <.update.>, <{uWhen}>,;
             <.design.>, <acBitmaps>, [{|nItem|<uBmpSelect>}], <nStyle>,;
             <cPicture>, [<{uEChange}>], [<(oCbx)>], <nHGet>, [<nSelHt>], [<nItmHt>], [<nDropW>], [<cDir>], ;
             [<attr>], [<oSayDir>] )


proc main()
   LOCAL oWnd, oCombo, oSay, cValue := ""
   DEFINE WINDOW oWnd
   @ 1,1 MYCOMBOBOX oCombo VAR cValue SIZE 200,200 STYLE CBS_DROPDOWN //ON EDIT CHANGE {|| MsgInfo(oCombo:GetText()) }
   @ 2,2 SAY oSay PROMPT cValue UPDATE SIZE 200,20
   // I must use both
   oCombo:oGet:bAfterChange := {|| oSay:SetText(oCombo:GetText()) }
   oCombo:oGet:bUpdate := oCombo:oGet:bAfterChange
   ACTIVATE WINDOW oWnd// ON INIT (oCombo:oGet:SetSel())

class MyComboBox inherit TComboBox
    CONSTRUCTOR New
endclass


class MyText inherit TEdit
    DATA bAfterChange
    METHOD KeyUp( nKey, nFlags ) INLINE iif(!empty(::bAfterChange),eval(::bAfterChange),), ::Super:KeyUp(nKey, nFlags)
endclass


#define COMBO_BASE      320
#define CB_FINDSTRING    ( COMBO_BASE + 12 )
#define COLOR_WINDOW         5
#define COLOR_WINDOWTEXT     8
#define GW_CHILD             5
// Copied from TComboBox:New
METHOD New( nRow, nCol, bSetGet, aItems, nWidth, nHeight, oWnd, nHelpId,;
    bChange, bValid, nClrFore, nClrBack, lPixel, oFont,;
    cMsg, lUpdate, bWhen, lDesign, acBitmaps, bDrawItem, nStyle,;
    cPict, bEChange, cVarName, nHGet, ;
    nSelHt, nItmHt, nListWidth, cDir, nAttr, oSayDir ) CLASS MyComboBox

if nClrFore == nil
nClrBack := GetSysColor( COLOR_WINDOW )
endif

DEFAULT nRow     := 0, nCol := 0, bSetGet := { || nil },;
   oWnd     := GetWndDefault(),;
   oFont    := oWnd:oFont,;
   aItems   := {}, nWidth := 40, nHeight := 60,;
   nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
   lPixel   := .f., lUpdate := .f., lDesign := .f.,;
   nStyle   := CBS_DROPDOWNLIST

::lUnicode  = FW_SetUnicode()
::cCaption  = ""
::nTop      = nRow * If( lPixel, 1, CMB_CHARPIX_H )
::nLeft     = nCol * If( lPixel, 1, CMB_CHARPIX_W )
::nBottom   = ::nTop  + nHeight - 1
::nRight    = ::nLeft + nWidth  - 1
::nAt       = 0
::aItems    = aItems
::bChange   = bChange
::bSetGet   = bSetGet
::uOriginalValue = Eval( ::bSetGet )
::oWnd      = oWnd
::cSearchKey := ""

if acBitmaps != nil
::SetBitmaps( acBitmaps )
else
::lOwnerDraw = .f.
/*
// FWH 17.07
if !Empty( nHGet )
 ::nBmpHeight := nHGet
endif
*/

endif

::nStyle    = nOR( If( nStyle == CBS_DROPDOWN, 0, LBS_NOTIFY ), WS_TABSTOP,;
              nStyle,;
              LBS_DISABLENOSCROLL, WS_CHILD, WS_VISIBLE, WS_BORDER,;
              WS_VSCROLL, If( lDesign, WS_CLIPSIBLINGS, 0 ),;
              IF( ::lOwnerDraw, CBS_OWNERDRAWFIXED, 0 ) )

//::nExStyle  = nOr( WS_EX_LEFT, WS_EX_LEFTSCROLLBAR )

::nId       = ::GetNewId()
::nHelpId   = nHelpId
::bValid    = bValid
::lDrag     = lDesign
::lCaptured = .f.
::cMsg      = cMsg
::lUpdate   = lUpdate
::bWhen     = bWhen
::bDrawItem = bDrawItem

::SetColor( nClrFore, nClrBack )

if oFont == nil
::GetFont()
else
::SetFont( oFont )
endif

::oGet := MyText():ReDefine( nil     ,;  // ID not used
                        Self        ,; //oWnd,
                        ::bSetGet   ,; //bSetGet,
                        cPict       ,; //cPicture,
                        nil         ,; //bChanged,
                        bEChange    ,; //bUpdate,
                        nil         ); //bHScroll )

// FWH 17.07
if cDir != nil
::cDir      := cDir
::lDir      := .t.
::nDirStyle := nAttr
::oSayDir   := oSayDir
endif
if nHGet != nil
::hSelectionHeight   := nHGet
::hItemHeight        := nHGet
else
::hSelectionHeight   := nSelHt
::hItemHeight        := nItmHt
endif
::hDropWidth         := nListWidth
// FWH17.07 end

if ! Empty( oWnd:hWnd )
::Create( "COMBOBOX" )
::Default()
::SetFont( ::oFont )
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif

DEFAULT cVarName := "oCbx" + ::GetCtrlIndex()

::cVarName = cVarName

::oGet:hWnd = GetWindow( ::hWnd, GW_CHILD )

if ! Empty( ::oGet:hWnd )
    ::oGet:Link()

::oGet:bLostFocus = ;
 { | hCtlFocus, nAt, cItem| cItem := ::GetText(), ;
     nAt := ::SendMsg( CB_FINDSTRING, 0, Trim( cItem ) ) + 1,;
     Eval( ::bSetGet, cItem ),;
     ::Select( nAt ),;
     ::SetText( cItem ),;
     If( ::bValid != nil .and. ;
     GetParent( hCtlFocus ) == GetParent( ::hWnd ),;
     If( ! Eval( ::bValid, ::oGet, Self ),;
     ::PostMsg( WM_SETFOCUS ),),) }
//::oGet:bKeyChar = { | nKey | ::GetKeyChar( nKey ) }
endif

if lDesign
::CheckDots()
endif

return Self
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 42 guests