Detect button caption based from listbox

  1. 4 months ago

    Arief S

    Jul 11 Bandung - Indonesia

    Hi,

    I have a Listbox data,

    Button1
    Button2
    Button3
    Button4

    and 4 buttons, the button's text based from Listbox row content.
    what I need is, if i do clicking the row, if the button text is equal with row selected text, then bold the text of button.
    Does this method is possible to do it in xojo ?

    Thanks,
    Regards,
    Arief

    Here's an example project that does not rely on string comparison to handle the bolding:
    Listbox Control Example

    It's very simple, you store the PushButton instance as a row tag and then the selected row is bolded without needing a control set.

  2. Dave S

    Jul 11 San Diego, California USA
    pushbutton1.bold=(listbox.text=pushbutton1.text)

    was the first thing to come to mind

  3. Arief S

    Jul 11 Bandung - Indonesia

    Hi Mr. Sisemore,

    the code is work only on a pushbutton1,
    I have 4 PushButtons, if I do select the row with equal text, the result could be button 1, 2,3 or 4, not only in button1

    Do I have to create an array button for this ?

    Thanks
    Regards,
    Arief

  4. Paul L

    Jul 17 Xojo Inc http://developer.xojo.com

    Dave's suggestion would work if you apply it to all your buttons. So you could do something like this in the ListBox.Change event handler:

    PushButton1.Bold = Me.List(Me.ListIndex) = PushButton1.Caption
    PushButton2.Bold = Me.List(Me.ListIndex) = PushButton2.Caption
    PushButton3.Bold = Me.List(Me.ListIndex) = PushButton3.Caption
    PushButton4.Bold = Me.List(Me.ListIndex) = PushButton4.Caption

    A control set might be cleaner if the number of buttons varies at all. So if your PushButton's are in a control set then this code in the ListBox.Change event handler would work:

    For i As Integer = 0 To 3
      PushButton1(i).Bold = Me.List(Me.ListIndex) = PushButton1(i).Caption
    Next
  5. Tim P

    Jul 17 Pre-Release Testers Answer feedback://46303
    Edited 4 months ago

    Here's an example project that does not rely on string comparison to handle the bolding:
    Listbox Control Example

    It's very simple, you store the PushButton instance as a row tag and then the selected row is bolded without needing a control set.

  6. Edwin v

    Jul 17 Pre-Release Testers, Xojo Pro The Netherlands

    @Paul L A control set might be cleaner

    Wow, Paul... I just started to write exactly that suggestion. But I got a call and ran off. Now you beat me to it.
    Yes, a controlSet is what I often use in this case.

    I kind of do the same thing with a PagePanel and a bunch of buttons in a controlSet. I loop through the pages and style the buttons accordingly.
    I use Rounded and Recessed buttons to tell which page I have selected. This way I have a nice clean Tab Panel, kind of thing.

  7. Arief S

    Jul 17 Bandung - Indonesia

    nice..!

    Thanks for all the helps..

    Regards,
    Arief

or Sign Up to reply!