/ Forums / Advansys Formativ / Creating Solutions with Formativ / Returning selected value from TrzListView

  • Creator
    Topic
  • #4285
    sfritz
    Participant

      Hi,

      Thank you for pointing me in the right direction regarding equivalents between selectboxes and listviews. I have the following code based on one of your examples in the forum:

      Sub Main(Client, GWEvent)
      dim I
      dim iGuidelines, iGuideline
      dim oItem
      dim userid
      userid = groupwise.account.owner
      ‘ Initialize a 3-dimensional array of data.
      iGuidelines = Array(Array(“Chronic Disease”, “1a”, “Annual community wide education campaign”), _
      Array(“Chronic Disease”, “1b”, “Community Events”), _
      Array(“Chronic Disease”, “1c”, “Coalition”), _
      Array(“Chronic Disease”, “1d”, “Telephone/Internet”), _
      Array (“Chronic Disease”, “1e”, “Variety of Channels”))

      ‘ This assumes a form MainForm with TRzListView named
      ‘ ListView which has three columns defined.
      with CDIP_FRM.ListView
      .Column(0).Caption = “Program”
      .Column(1).Caption = “Guideline #”
      .Column(2).Caption = “Guideline”
      .Items.BeginUpdate
      .Items.Clear
      for I = 0 to UBound(iGuidelines)
      iGuideline = iGuidelines(I)
      set oItem = .Items.Add
      oItem.Caption = iGuideline(0)
      oItem.SubItems.Add(iGuideline(1))
      oItem.SubItems.Add(iGuideline(2))
      next
      .Items.EndUpdate
      end with
      CDIP_FRM.SHOWMODAL
      End Sub

      When the user places a check beside one of the guidelines I only want to write the guideline # out to the database. I have tried itemindex, item.checked, itemselected property and used a for loop etc but obviously missing something. This is a static list and the guideline # is the key to the guidelines table and more or more guidelines can be used.

      Thanks, I appreciate your help. You are very prompt and efficient with your responses and I just wanted to say thank you. I enjoy the product and the benefit of excellent support.

    • Author
      Replies
    • #7719
      Support 3
      Participant

        Use ListItem.SubItems to read the value relate to the column. SubItems is a TStrings (Delphi) which is the base class for objects that represent a list of strings. Some common properties and methods of the SubItems are: count, commatext, text, indexof.

        See the sample code below to read the selected item SubItems value. Index gives the position of the string, where 0 is the position of the first string, 1 is the position of the second string, and so on.

          
        if (CDIP_FRM.ListView.itemindex < 0) then
          msgbox("Select an item from the list to proceed.")
          CDIP_FRM.ListView.setfocus
          exit sub
        end if
        
        set oListItem = CDIP_FRM.ListView.selected
        
        msgbox oListItem.Caption & vbcrlf &_
        oListItem.SubItems.Strings(0) & vbcrlf &_
        oListItem.SubItems.Strings(1)
        

        Hope this helps.

        Regards,
        Advansys Support

      Viewing 1 replies (of 1 total)
      • You must be logged in to reply to this topic.