Help : Is it possible to display a tree on DbCombo ?

Help : Is it possible to display a tree on DbCombo ?

Postby anserkk » Wed Sep 24, 2008 8:01 am

Dear Friends,

Is it possible to display a tree on DbCombo ?.

For Eg: Displays Dept.Name and when the user selects a Tree Item Dept.Code should be returned

Right now I am using DbCombo with array imitating like a tree (By adding space to the left of each array element).

One of the problems is that the space added to the left of array element. Because of this reason incremental search will not work

I checked the sample aTree.Prg in the FWH Samples, but it seems that the display and navigation of the tree is not perfect on Tree when placed on a ListBox

Screen Snapshot

Image

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby James Bott » Wed Sep 24, 2008 10:40 am

Anser,

No it is not possible to display in a tree format. Even if it was, you could still not do an incremental search since your data is not in alpha order.

The solution you have aleady come up with is probably the best you can do.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby anserkk » Wed Sep 24, 2008 11:30 am

Thankyou Mr.James for your valuable opinion and views in this regard.

Would have been nice If we had similiar tool in future. Hope Mr.Antonio will consider this requirement in future. This tool/control will be useful only
for displaying/selecting hierarchical data.

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby Silvio » Wed Sep 24, 2008 11:56 am

james ,
I saw tree in combobox some years ago but I not found this class
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby James Bott » Wed Sep 24, 2008 12:33 pm

Anser,

>Would have been nice If we had similiar tool in future. Hope Mr.Antonio will consider this requirement in future. This tool/control will be useful only for displaying/selecting hierarchical data.

I'm not sure what advantage it would have over what you are using now.

You can always make your own by calling it from the new GET...ACTION clause. Just make a dialog or window containing the tree.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby anserkk » Wed Sep 24, 2008 1:35 pm

Dear Mr.James,

The array which I am using right now with the DBCOMBO returns the list element along with the spaces which I have added in the left.

If you look at the above posted screen snapshot, you will notice that the Account group : instead of
"Consumable stores" it will display " Consumable stores".

May be I will have to find a way to do a Ltrim on the DBCombo List after the user has selected.

You are right. As said by you, we can always develop our own tools using the available controls, which Mr.Antonio has already provided. I am very much new to Windows programming and I am hunting for samples to have a better start in the right direction.

Regards

Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby James Bott » Wed Sep 24, 2008 2:46 pm

Anser,

>If you look at the above posted screen snapshot, you will notice that the Account group : instead of "Consumable stores" it will display " Consumable stores".

Understood.

>May be I will have to find a way to do a Ltrim on the DBCombo List after the user has selected.

I'm not sure why you need to deal with this. Aren't you returning the account number? If so, then how the data is displayed to the user has no effect on the data you are collecting.

Maybe you are not using DBCombo the way it was designed to be used?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby StefanHaupt » Thu Sep 25, 2008 7:37 am

Anser, Silvio,

I found this extended Combobox-class from Oscar Joel, maybe it helps


Code: Select all  Expand view
/*#################################################################################################
#  $Id: $
#  Lira Lira Oscar Joel [_]
#  Proyecto     : CommCtrl32
#  Archivo      : comboex.prg
#  Creacion     : 07/09/2006, 10:39
#  Actualizacion: :>: 07/14/2006 13:14
#################################################################################################*/
/*
   20060714 - Modificacion necesaria en la clase TWindow y TDialog Metodo Command
   Para el correcto funcionamiento de este control es necesario modificar la clase TWindow y TDialog
   de Fivewin para direccionar las notificaciones al control, la modificacion es la siguiente
   en el metodo Command( nWParam, nLParam ), y declarar la variable nControl como local en el mismo
   metodo

      case GetClassName( hWndCtl ) == "ToolbarWindow32"
         oWndFromHwnd( hWndCtl ):Command( nWParam, nLParam )

      // Inicia Modificacion
      // Trasladamos los mensajes al control ComboBoxEx32

      CASE GetClassName( hWndCtl ) == "ComboBoxEx32"
         nControl := AScan( ::aControls, { |oControl| oControl:hWnd == hWndCtl } )
         IF nControl > 0
            ::aControls[ nControl ]:Command( nWParam, nLParam )
         ENDIF


      // Fin de la modificacion

      case hWndCtl != 0
*/

#include "Fivewin.ch"
#define CB_GETCOUNT             0x0146
#define CB_GETCURSEL            0x0147
#define CB_SETCURSEL            0x014E
#define CB_SHOWDROPDOWN         0x014F
#define CBEM_SETIMAGELIST       0x0402
#define CBEM_GETEDITCONTROL     0x0407
#define CBN_SELCHANGE           0x0001
#define SWP_NOACTIVATE          0x000G
#define WM_SETTEXT              0x000C

/*-----------------------------------------------------------------------------------------------*/
FUNCTION MainEx()
   LOCAL nOp
   nOp := MsgList( { "En una Ventana desde codigo"   ,;
                     "En un Dialogo desde codigo"    ,;
                     "En un Dialogo desde recursos" },;
                   "DEMO TComboBoxEx by _" )
   DO CASE
      CASE nOp == 1
         Test01()
      CASE nOp == 2
         Test02()
      CASE nOp == 3
         Test03()
   ENDCASE
   MsgInfo( "Gracias por testear este control Dudas o comentarios," + CRLF +;
            "envia un email a oscarlira78@hotmail.com"              + CRLF +;
            "http://_...net" )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test01()
   LOCAL oWnd, oCbx

   DEFINE Window oWnd

      oWnd:SetText( "_ ComboBoxEx Demo" )
      oCbx := TComboboxEx():New( oWnd, 50, 10, 300, 40 )
      ConfiguraCbx( oCbx )
      oWnd:bRClicked := { || Alert( oCbx:nAt ) }

   Activate Window oWnd
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test02()
   LOCAL oDlg, oCbx
   DEFINE Dialog oDlg
   Activate Dialog oDlg Center ON Init;
      ( oCbx := TComboboxEx():New( oDlg, 50, 10, 300, 40 ),;
        ConfiguraCbx( oCbx ) )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test03()
   LOCAL oDlg, oCbx
   DEFINE Dialog oDlg Resource "DL_COMBOEX"
   Activate Dialog oDlg ON Init ;
      ( oCbx := TComboBoxEx():New( oDlg,,,,,,,101 ),;
        ConfiguraCbx( oCbx ) )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
FUNCTION ConfiguraCbx( oCbx )
   WITH OBJECT oCbx
      :AddImage( 101 )
      :AddImage( 102 )
      :AddImage( 103 )
      :SetImageList()
      :AddItem( "The"    , 0, 0 )
      :AddItem( "Fivewin", 1, 1 )
      :AddItem( "Power"  , 2, 2 )
      :AddItem( "Test"   , 0, 0 )
      :AddItem( "by"     , 1, 1 )
      :AddItem( "_"  , 2, 2 )
      :Activate()
      :bChange := { || MsgInfo( oCbx:cVar ) }
   END
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
CLASS TComboBoxEx FROM TControl
   DATA nTop, nLeft, nWidth, nHeight
   DATA nBmpHeight
   DATA nBmpWidth
   DATA oImageList
   DATA aTags                   INIT {}
   DATA hGet
   DATA lResource               INIT .T.
   METHOD New()                 CONSTRUCTOR
   METHOD AddItem()
   METHOD AddImage()
   METHOD SetImageList()        INLINE ::SendMsg( CBEM_SETIMAGELIST, 0, ::oImageList:hImageList )
   METHOD Count()               INLINE ::SendMsg( CB_GETCOUNT      , 0, 0 )
   METHOD Activate()            INLINE IF( !::lResource, SetWindowPos( ::hWnd, NIL, ::nTop, ::nLeft, ::nWidth, ::nHeight, SWP_NOACTIVATE ), NIL )
   METHOD nAt( nPos )           SETGET
   METHOD ShowDropDown( lShow ) INLINE IF( Empty( lShow ), lShow := .T., NIL ), ::SendMsg( CB_SHOWDROPDOWN, lShow )
   METHOD cVar( cText )         SETGET
   METHOD Change()              INLINE IF( !Empty( ::bChange ), Eval( ::bChange ), NIL )
   METHOD Command()
ENDCLASS

/*-----------------------------------------------------------------------------------------------*/
METHOD New( oWnd, nTop, nLeft, nHeight, nWidth, nBmpWidth, nBmpHeight, nId )
   LOCAL oImageList, aRect, lResource, aRect2
   DEFAULT nTop       := 000,;
           nLeft      := 000,;
           nWidth     := 100,;
           nHeight    := 100,;
           nBmpWidth  := 016,;
           nBmpHeight := 016

   IF Empty( nId )
      ::lResource := .F.
      nId       := ::GetNewId()
   ENDIF

   ::oWnd       := oWnd
   ::nTop       := nTop
   ::nLeft      := nLeft
   ::nWidth     := nHeight
   ::nBmpWidth  := nBmpWidth
   ::nBmpHeight := nBmpHeight
   ::nId        := nId

   ::oImageList := TImageList():New( ::nBmpWidth, ::nBmpHeight )

   IF! Empty( oWnd:hWnd )
      IF !::lResource
         ::hWnd := CBExCreate( ::oWnd:hWnd, ::nId, GetInstance() )
      ELSE
         ::hWnd    := GetDlgItem( ::oWnd:hwnd, nId )
      ENDIF
      ::hGet := ::SendMsg( CBEM_GETEDITCONTROL )
      ::oWnd:AddControl( SELF )
   ELSE
      Alert( "De momento debes de iniciar el control en el on init del dialogo" )
   ENDIF
   RETURN SELF

/*-----------------------------------------------------------------------------------------------*/
METHOD AddImage( cResource, cTag )
   DEFAULT cTag := cResource
   ::oImageList:AddMasked( TBitmap():Define( cResource, , ::oWnd ), nRGB( 255, 0, 255 ) )
   AAdd( ::aTags, cTag )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD AddItem( cItem, nImage, nIndent )
   DEFAULT cItem   := "",;
           nImage  := 0 ,;
           nIndent := 0
   IF ValType( nImage ) == "C"
      nImage := AScan( ::aTags, { |cTag| cTag = nImage } )
   ENDIF

   CBExAddItem( ::hWnd, cItem, nImage, nIndent, ::Count() )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD nAt( nItem )
   IF PCount() > 0
      RETURN ::SendMsg( CB_SETCURSEL, nItem - 1, 0 )
   ENDIF
   RETURN ::SendMsg( CB_GETCURSEL, 0, 0 ) + 01

/*-----------------------------------------------------------------------------------------------*/
METHOD cVar( cText )
   LOCAL nAt
   IF PCount() > 0
      RETURN ::SendMsg( WM_SETTEXT, 0, cText )
   ENDIF
   nAt := ::nAt
   IF nAt > 0
      RETURN CBExGetTlbText( ::hWnd, ::nAt - 1 )
   ENDIF
   RETURN ""

/*-----------------------------------------------------------------------------------------------*/
METHOD Command( nWParam, nLParam )
   LOCAL nCode
   nCode   = nHiWord( nWParam )
   DO CASE
      CASE nCode == CBN_SELCHANGE
         ::Change()
   ENDCASE
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
#pragma BEGINDUMP
   #include <windows.h>
   #include <commctrl.h>
   #include "hbapi.h"
   /*--------------------------------------------------------------------------------------------*/
   HB_FUNC( CBEXCREATE ){ //hWnd, nId, hInstance
      HWND hWnd;
      hWnd = CreateWindowEx( 0, WC_COMBOBOXEX, (LPSTR) NULL,
                             WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST,
                             0, 0, 0, 100,
                             (HWND) hb_parnl( 1 ),
                             (HMENU) hb_parnl( 2 ),
                             (HINSTANCE) hb_parnl( 3 ),
                             NULL);
      hb_retnl( (long) hWnd );
   }

   /*--------------------------------------------------------------------------------------------*/
   HB_FUNC( CBEXADDITEM ){ // hwndCB, cItem, nImage, nIndent, nIndex
      COMBOBOXEXITEM cbei;
      cbei.iItem          = hb_parni( 5 );
      cbei.pszText        = hb_parc( 2 );
      cbei.cchTextMax     = sizeof( hb_parc( 2 ) );
      cbei.iImage         = hb_parni( 3 );
      cbei.iSelectedImage = hb_parni( 3 );
      cbei.iIndent        = hb_parni( 4 );
      cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
      hb_retni( SendMessage( (HWND) hb_parnl( 1 ),CBEM_INSERTITEM,0,(LPARAM)&cbei) );
   }

   /*--------------------------------------------------------------------------------------------*/
   HB_FUNC( CBEXGETTLBTEXT ){ //hWndCB, nItem
      char cBuffer[255];
      SendMessage( (HWND)hb_parnl( 1 ), CB_GETLBTEXT, hb_parni( 2 ), (LPARAM)&cBuffer );
      hb_retc( cBuffer );
   }
#pragma ENDDUMP
/*-----------------------------------------------------------------------------------------------*/
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby anserkk » Thu Sep 25, 2008 7:56 am

Thankyou Stefan
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 68 guests