Menu

#64 hBrowse and logical field with CheckBox

v1.0_(example)
open
nobody
None
1
2023-11-30
2023-11-24
No

Hi!
How to use a CheckBox into picture of dbf field logical with browse ?

Best regards,
Itamar M Lins Jr.

Discussion

  • Itamar M. Lins Jr.

    Hi!
    Because i use for show and edit a logical column of browse checkbox picture.
    But this version SVN show F or T into field logical.

    Best regards,
    Itamar M. Lins Jr.

     
  • Alexander S.Kresin

    Hello,
    there are, at least, two ways to do this.
    The first one - using the HColumn():aBitmaps array of pairs { bCondition, oBmp } - if a result of bCondition is .t., the appropriate bitmap is drawn. See the example in samples/a.prg, Openabout() function.
    The second - using of HPaintCB class, see the tutorial, "Advanced using of controls"/Browse:
    oBrw:aColumns[1]:oPaintCB := HPaintCB():New()
    oBrw:aColumns[1]:oPaintCB:Set( PAINT_LINE_ALL, bCol1 )

    In that sample the bCol1 codeblock draws a gradient background only, but you can draw there all what you need, including the bitmap.

    Regards, Alexander.

     
    • Itamar M. Lins Jr.

      Hi!
      First option not work with mouse click, only with "space bar". keyboard and array browse, I use DBF browse.
      And the second option I don't understand how I'm going to use it.

      Local bCol1 := {|o,h,x1,y1,x2,y2|
         oStyle:Draw( h,x1,y1,x2,y2 )
         RETURN Nil
      }
      

      Is correct this syntaxe ? (return nil)
      How to put checkbox control in get line of browse ?

      Best regards,
      Itamar M. Lins Jr.

       
  • Alexander S.Kresin

    Both options are intended to display the checkbox. To change it you may use few other ways. One of them, via the oBrw:bKeyDown, is in a.prg. If you want to change the field by mouse doubleclick or enter, you need to use the bEnter block, something like this:

    Local bEnter := {|o,nc|
    IF nc == 1 // nc is a column number
    o:aArray[ o:nCurrent,1 ] := !o:aArray[ o:nCurrent,1 ]
    // Or, for a dbf browse:
    // ( o:alias ) -> (rlock()) // if in shared mode
    // ( o:alias ) -> SomeField := !( o:alias ) -> SomeField
    // ( o:alias ) -> (dbUnlock())
    o:RefreshLine()
    ENDIF
    RETURN .T.
    }
    ...
    oBrw:bEnter := bEnter

    What about displaying checkbox, using the HPaintCB, see the tutorial, "Advanced using of controls", "Browse of bitmaps", bCol2 codeblock. To change it, you may use the same trick with bEnter.

    Regards, Alexander

     
    • Itamar M. Lins Jr.

      Hi!
      First option not show column on Linux GTK.

      #include "hwgui.ch"
      FUNCTION Main()
      local oDlg, oBrw
      
         aStructure := { { "idcontact" ,"+",04,0} ,; //Auto increment
                         { "mark"      ,"l",01,0} ,;
                         { "name"      ,"c",60,0} }
      
         If !hb_vfexists("contacts.dbf")      
            If dbcreate("contacts.dbf",aStructure,,.t.,"ctc") //Create and open with shared mode
               index on field->name tag tgName
               ctc->( dbappend() )
               ctc->name := "JOSÉ DE ASSUMPÇÃO"
               ctc->( dbappend() )
               ctc->name := "MARIA ANTONIETA"
               ctc->( dbappend() )
               ctc->name := "SNOOPY"
               ctc->( dbappend() )
               ctc->name := "POPEYE"
               ctc->(DbDelete())
      
               ctc->( dbCloseArea() )
            Else
               hwg_MsgStop("Error Creating DBF")
               cancel
            EndIf
         EndIf
      
      Use contacts new shared alias "ctc"
      
      INIT DIALOG oDlg TITLE "TEST" AT 0, 0  SIZE 800, 600 
      
         @ 10, 10 BROWSE oBrw DATABASE of oDlg SIZE 200, 200
      
         oBrw:Alias:="ctc"
      
         Add Column FieldBlock("mark") to oBrw Header "mark" Length 20
      
         Add Column FieldBlock("idcontact") to oBrw  Header "Cont_ID" Length 10
      
         Add Column FieldBlock("name") to oBrw Header "Name" length 100
      
         oBmp := HBitmap():AddStandard( "gtk_apply" ) //"gtk_ok"
         oBrw:aColumns[1]:aBitmaps := { { {|l|l}, oBmp } }
      
      
      oDlg:Activate()
      
      close all
      hb_vferase("contacts.dbf")
      Return nil
      

      Best regards,
      Itamar M. Lins Jr.

       
  • Alexander S.Kresin

    1) No "gtk_apply", but "gtk-apply"
    2) There are no records with a mark = .t. in your dbf

    Regards, Alexander.

     
    • Itamar M. Lins Jr.

      Hi!
      I saw(found) your example in the tutor program -> DRAWN BROWSE.(oBrw2)
      But it doesn't work in traditional browse.
      A get error HANDLE.

      Probably along these lines -> hwg_Fillrect( h, x1, y1, x2, y2, ob:handle )

      And DRAWN BROWSE I not found method ON POSTCHANGE.

      Best regards,
      Itamar M. Lins Jr.

       
    • Itamar M. Lins Jr.

      Hi!
      More info about use in Linux OS.
      Note that the check mark only appears when the browse line receives cursor focus

      Best regards,
      Itaamr M. Lins Jr.

       
  • Alexander S.Kresin

    Hmm... It appears normally here, on my Linux computer.

     
  • Alexander S.Kresin

    I've added new sample module to the tutorial, "Array of browse" with displaying/editing logical fields.

    Regards, Alexander

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.