Announcement

Collapse
No announcement yet.

Problems with a simple Listbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with a simple Listbox

    I am trying to use a list box to let the user select and open PDF files. I have populated the list box with the document name in the item text column and in the item data column--I have populated it using the built in "insert file reference" command. The help file says it is easy to select an item in the list box and use the inserted file reference to open the file. How do you do this?

    I have tried the following code but it does not work. It seems the File.Open command cannot handle a variable as the path.

    PHP Code:
    List_Select ListBox.GetSelected("ListBox1");
    data_string ListBox.GetItemData("ListBox1"List_Select);
    File.Open(data_string"PDFs"SW_MAXIMIZE); 
    I have searched through what now seems to be very few online resources about a listbox. The youtube videos by IR don't show how to do this or at least after hours of searching, I have given up Thank you. JimC

  • #2
    As List_Select is a table, you need to use
    Code:
    data_string = ListBox.GetItemData("ListBox1", List_Select[1]);
    to retrieve the item data of the (first) selected item.

    Ulrich

    Comment


    • #3
      Ulrich,
      Thank you.

      I am not sure where I saw or read how to get the code I posted...and it may have even been for an older version of AMS, but I was under the impression that an array or table is only created when I would click the check box to permit "multiple selection" in the listbox. I guess that was incorrect advice.

      Originally, the end user only want to open one item in the list box at a time but now I have been asked to permit multiple selection. So I will click the check box to permit multiple selection. But I am now struggling trying to build a "loop" to open each pdf that is selected. How do you do this? Is there some sort of "end of table" indicator to halt the loop processing. I cannot discern "how to halt the loop processing" when all the pdf's selected have been opened.

      Thank you for your patience.
      JimC

      Comment


      • #4
        Originally posted by Waldo View Post
        Originally, the end user only want to open one item in the list box at a time but now I have been asked to permit multiple selection. So I will click the check box to permit multiple selection. But I am now struggling trying to build a "loop" to open each pdf that is selected. How do you do this? Is there some sort of "end of table" indicator to halt the loop processing. I cannot discern "how to halt the loop processing" when all the pdf's selected have been opened.
        First, you would use ListBox.GetCheckedCount() and see if this returns a number greater than 0, meaning that there is at least 1 item checked. If there is something checked, then you would construct a loop starting from 1 to the count of checked items, and retrieve the items with ListBox.GetChecked() instead of ListBox.GetSelected() in your previous code. Something like this:

        Code:
        local nCount = ListBox.GetCheckedCount("ListBox1", BST_CHECKED);
        if (nCount >= 0) then
            local tChecked = ListBox.GetChecked("ListBox1", BST_CHECKED);
            for i = 1, nCount do
                local sFilePath = ListBox.GetItemData("ListBox1", tChecked[i]);
                File.Open(sFilePath, "", SW_NORMAL);
            end
        end
        Ulrich

        Comment


        • #5
          Ulrich---thank you for taking the time to use your talent to help others. This is greatly appreciated. Take care. Jim

          Comment

          Working...
          X