Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:52:50+00:00 2026-06-18T07:52:50+00:00

I have two ListView’s. One has options that are to be dragged into the

  • 0

I have two ListView’s. One has options that are to be dragged into the other. This is the “fields” ListView. The other one is the “builder” ListView. The problem I am having is that I cannot have ListViewItem’s inserted where the user drags it AND also be added to the bottom if they drag it to whitespace. I can do one or the other at this time. I need a solution for this.

private void builder_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

private void fields_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

private void fields_ItemDrag(object sender, ItemDragEventArgs e)
{
    fromBuilder = false;
    fields.DoDragDrop(e.Item, DragDropEffects.Move);
}

private void builder_ItemDrag(object sender, ItemDragEventArgs e)
{
    fromBuilder = true;
    builder.DoDragDrop(e.Item, DragDropEffects.Move);
}

private void builderAndFields_DragDrop(object sender, DragEventArgs e)
{
    ListViewItem i = new ListViewItem();
    i = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;

    // Since this function works for both the builder and the fields,
    // we have to check to see where we are dropping, the sender
    // is the ListView we are dropping onto
    if (sender.Equals(builder))
    {
        ListViewItem c = new ListViewItem();
        c = (ListViewItem)i.Clone();
        Point cp = builder.PointToClient(new Point(e.X, e.Y));
        Console.WriteLine("cp: " + cp);
        ListViewItem dragToItem = builder.GetItemAt(cp.X, cp.Y);
        Console.WriteLine("dragToItem: " + dragToItem);
        int dropIndex = dragToItem.Index;
        // Now, we have to check to see if we are reordering or adding
        // So, we check the flag to see if the dragDrop was initiated 
        // on the builder or on the fields ListView
        if (fromBuilder)
        {
            builder.Items.Insert(dropIndex, c);
            builder.Items.Remove(i);
        }
        else
        {
            // ## Problem - Attempted solution ##
            if (String.IsNullOrWhiteSpace(dragToItem.ToString()))
                builder.Items.Add(c);
            else
            {
                Console.WriteLine(dropIndex);
                builder.Items.Insert(dropIndex, c);
            }
        }
    }
    // If the sender is the fields listView, the user is trying to remove
    // the item from the builder.
    else
    {
        builder.Items.Remove(i);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:52:51+00:00Added an answer on June 18, 2026 at 7:52 am

    Thank you for your comment Hans. It was very helpful! Here is the solution to two problems I was having. The other was being able to reorder the ListView and drag items to the bottom of the list.

    // Generic DragEnter
    private void ddEnter_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Move;
    }
    
    // ItemDrag Events
    private void fields_ItemDrag(object sender, ItemDragEventArgs e)
    {
        fromBuilder = false;
        fields.DoDragDrop(e.Item, DragDropEffects.Move);
    }
    
    private void builder_ItemDrag(object sender, ItemDragEventArgs e)
    {
        fromBuilder = true;
        packetBuilder.DoDragDrop(e.Item, DragDropEffects.Move);
    }
    
    // DragDrop Events
    private void builderAndFields_DragDrop(object sender, DragEventArgs e)
    {
        ListViewItem i = new ListViewItem();
        i = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
    
        // Since this function works for both the builder and the fields,
        // we have to check to see where we are dropping, the sender
        // is the ListView we are dropping onto
        Console.WriteLine(sender.Equals(packetBuilder));
        if (sender.Equals(packetBuilder))
        {
            ListViewItem c = new ListViewItem();
            c = (ListViewItem)i.Clone();
            Point cp = packetBuilder.PointToClient(new Point(e.X, e.Y));
            // Now, we have to check to see if we are reordering or adding
            // So, we check the flag to see if the dragDrop was initiated 
            // on the builder or on the fields ListView
            Console.WriteLine(fromBuilder);
            if (fromBuilder)
            {
                if (packetBuilder.HitTest(cp).Location.ToString() == "None")
                {
                    packetBuilder.Items.Add(c);
                    packetBuilder.Items.Remove(i);
                }
                else
                {
                    ListViewItem dragToItem = packetBuilder.GetItemAt(cp.X, cp.Y);
                    int dropIndex = dragToItem.Index;
                    packetBuilder.Items.Insert(dropIndex, c);
                    packetBuilder.Items.Remove(i);
                }
    
            }
            else
            {
                if (packetBuilder.HitTest(cp).Location.ToString() == "None")
                    packetBuilder.Items.Add(c);
                else
                {
    
                    ListViewItem dragToItem = packetBuilder.GetItemAt(cp.X, cp.Y);
                    int dropIndex = dragToItem.Index;
                    packetBuilder.Items.Insert(dropIndex, c);
                }
            }
        }
        // If the sender is the fields listView, the user is trying to remove
        // the item from the builder.
        else
        {
            packetBuilder.Items.Remove(i);
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is that I have two listView but one itemClick method, if I
If I have two activities in my app, one with listview and the other
I have a listview with several items that are created dynamically, each has two
I have two other apps that use a ListView and SimpleCursorAdapter . The code
I have two user controls on the same page. One contains a ListView that
I have two ItemsControls, one a ListView, and one a custom control I am
I have two views in my ViewFlipper . One of views contains a ListView
I have ListView that uses a GridView to display several columns of data. Two
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have two (or more) ListView's that are side by side. I need them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.