Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF ListBoxView Problem

WPF ListBoxView Problem

Scheduled Pinned Locked Moved WPF
helpcsharpwpfdatabasegraphics
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alisaunder
    wrote on last edited by
    #1

    I' making a very simple app to drag files from my desktop or explorer into a WPF ListBoxView, these files will be auto backed up on a specific day and time. I have the dragging files into the ListBoxView working fine. Can even insert Multiple selected at one time. I can rearrange my list order by dragging and dropping fine as well. My issue is I can't seem to trigger it to remove the file I drag out of the ListBoxView control to remove it from the List. Can anyone help ?? My Xaml

    My C#

    private void DropList_Drop(object sender, DragEventArgs e)
    {
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    foreach (string data in files)
    {
    if (!dropList.Items.Contains(data))
    dropList.Items.Add(data);
    }
    }
    else
    {
    object data = e.Data.GetData(typeof(string));
    dragSource.Items.Remove(data);
    dropList.Items.Add(data);
    }
    }

        private void DropList\_MouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;
    
            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemP
    
    L 1 Reply Last reply
    0
    • A Alisaunder

      I' making a very simple app to drag files from my desktop or explorer into a WPF ListBoxView, these files will be auto backed up on a specific day and time. I have the dragging files into the ListBoxView working fine. Can even insert Multiple selected at one time. I can rearrange my list order by dragging and dropping fine as well. My issue is I can't seem to trigger it to remove the file I drag out of the ListBoxView control to remove it from the List. Can anyone help ?? My Xaml

      My C#

      private void DropList_Drop(object sender, DragEventArgs e)
      {
      if (e.Data.GetDataPresent(DataFormats.FileDrop))
      {
      string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
      foreach (string data in files)
      {
      if (!dropList.Items.Contains(data))
      dropList.Items.Add(data);
      }
      }
      else
      {
      object data = e.Data.GetData(typeof(string));
      dragSource.Items.Remove(data);
      dropList.Items.Add(data);
      }
      }

          private void DropList\_MouseMove(object sender, MouseEventArgs e)
          {
              // Get the current mouse position
              Point mousePos = e.GetPosition(null);
              Vector diff = startPoint - mousePos;
      
              if (e.LeftButton == MouseButtonState.Pressed &&
                  (Math.Abs(diff.X) > SystemP
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Quote:

      My issue is I can't seem to trigger it to remove the file I drag out of the ListBoxView control to remove it from the List.

      If you are just "removing", there is no "dragging", unless it's to a "trash bin". Then do the "remove" in the drop event for the "trash". Otherwise, you simply delete the entry; usually with a right-click context menu or a delete key. (Though a trash bin does not make sense in this context because you are dealing with "file names", and not actual files in terms of what's removed).

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      A 1 Reply Last reply
      0
      • L Lost User

        Quote:

        My issue is I can't seem to trigger it to remove the file I drag out of the ListBoxView control to remove it from the List.

        If you are just "removing", there is no "dragging", unless it's to a "trash bin". Then do the "remove" in the drop event for the "trash". Otherwise, you simply delete the entry; usually with a right-click context menu or a delete key. (Though a trash bin does not make sense in this context because you are dealing with "file names", and not actual files in terms of what's removed).

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        A Offline
        A Offline
        Alisaunder
        wrote on last edited by
        #3

        Thank you I managed to get it to work using the Drag to trash like you suggested. I simply added a Stack panel that stretched Horizontally to give the user plenty of room to click on added an icon and label, works perfect. Although if you help me figure out how to catch multiple selected files being dragged from the ListBoxView to the trash It would be better, right now it's single file only. Having the option to drag one or multi is nice. I will go ahead and mark this solved since you did help me solve the original issue.

        L 1 Reply Last reply
        0
        • A Alisaunder

          Thank you I managed to get it to work using the Drag to trash like you suggested. I simply added a Stack panel that stretched Horizontally to give the user plenty of room to click on added an icon and label, works perfect. Although if you help me figure out how to catch multiple selected files being dragged from the ListBoxView to the trash It would be better, right now it's single file only. Having the option to drag one or multi is nice. I will go ahead and mark this solved since you did help me solve the original issue.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          For a multi-select, you should start thinking of using an ObservableCollection and updating that; that way changes are reflected back to the ListBox and you're not updating the ListBox yourself (and can ignore any ListBox events). The multi-selections represent keys into your ObservableCollection; which could br shadowed with a dictionary.

          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups