Announcement

Collapse
No announcement yet.

Listbox delete item

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

  • Listbox delete item

    hi to all
    I have a listbox with more than 100 *.txt files in the following directory:
    C:\Users\MyName\AppData\Roaming\Booking\textfiles
    text file names will be random and unknown
    =========================================
    Code:
    --add to listbox--
    text = Shell.GetFolder(26);
    files = File.Find(text.."\\Booking\\textfiles", "*.*", false, false, nil);
    if files ~= nil then
    min = 1;
    max = Table.Count(files);
    ListBox.DeleteItem("ListBox1", LB_ALLITEMS)
    for count = min, max do
    split = String.SplitPath(files[count]);
    result = ListBox.AddItem("ListBox1", split.Filename..split.Extension, files[count]);
    end
    else
    Dialog.Message("WARNING", "Files not found!");
    ListBox.SetEnabled("ListBox1", false);
    end
    =========================================
    checked Options in listbox properties:
    "Checklist"
    "Multiple selection"
    "Sort"
    "Vertical scrollbar"

    the "Item text" i left blank
    the "item Data" i numbered from 1 to 300 (just in case)

    So if i'll check some text file from listbox
    By using button i would like to delete selected text file from my directory as well as from listbox.

    I know how to delete from listbox by using "ListBox.DeleteItem"
    But can't delete that file from directory in the same time

    Please helm me how to do.​

  • #2
    ListBox Example

    Comment


    • #3
      Originally posted by herrin View Post
      Thank you,
      That's good to have better code than mine!
      But i need another code to delete selected text file from location and from listbox with button "Delete selected file".

      Comment


      • #4


        Code:
        tSelected = ListBox.GetSelected("ListBox1");
        if tSelected then
        sFilePath = ListBox.GetItemData("ListBox1", tSelected[1]);
        ListBox.DeleteItem("ListBox1", tSelected[1]);
        File.Delete(sFilePath, false, false, false, nil);
        end

        Comment


        • #5
          Originally posted by herrin View Post

          Code:
          tSelected = ListBox.GetSelected("ListBox1");
          if tSelected then
          sFilePath = ListBox.GetItemData("ListBox1", tSelected[1]);
          ListBox.DeleteItem("ListBox1", tSelected[1]);
          File.Delete(sFilePath, false, false, false, nil);
          end
          Thank you Herrin! that's all i need! it works perfectly.
          Now i have another problem, so when i check some item from listbox and checked file will shows in the input box where i will be able to read and edit the text file.
          After editing i would like to make the button to save the changes have been made. the text in each files will be different so i just need to save the changes using "save" button.
          something like this:
          Code:
          if ListBox.IsItemSelected("ListBox1", 1) then
          Input.SetText("Input1", TextFile.ReadToString("selected file from path "));
          And on button "save" i can't figure out how to do.
          Can you help me about that?​

          Comment


          • #6
            ListBox Reworked

            Comment


            • #7
              Originally posted by herrin View Post
              It was so good!
              Thank you!
              Now i can't say to my friends that i am autor of that small utility
              90% of work was yours!
              Thank you again
              Adam!

              Comment


              • #8
                ListBox Reworked​ Link dead brother, can u upload again please??

                Comment


                • #9
                  reupload:
                  ListBox & Text File

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎