Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are two listboxes and two textboxes on my form. The names are lbxSubjects, lbxCompanies, txtSubject and txtCompany repectively. I have drag and drop coded for each. The problem is when drag a item from the Subjects listbox not only can you drop it in the Subject textbox, it also will drop in the Company textbox. The same thing happens with Company also.

I want Subject to go Subject and Company to go Company. What am I doing wrong? This is my first drag and drop operation. Here is the drag and drop code.

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

private void txtSubject_DragEnter(object sender, DragEventArgs e)
{
    txtSubject.Text = (string)e.Data.GetData(DataFormats.Text);
}

  private void lbxSubjects_MouseDown(object sender, MouseEventArgs e)
{
    lbxSubjects.DoDragDrop(lbxSubjects.SelectedItem.ToString(),
    DragDropEffects.Copy);
}

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

private void txtFindCompany_DragEnter(object sender, DragEventArgs e)
{
    txtCompany.Text = (string)e.Data.GetData(DataFormats.Text);
}

private void lbxCompanies_MouseDown(object sender, MouseEventArgs e)
{
    lbxCompanies.DoDragDrop(lbxCompanies.SelectedItem.ToString(),
    DragDropEffects.Copy);
}


What I have tried:

I have read several articles on drag and drop but have nothing on this issue.
Posted
Updated 4-Feb-22 15:46pm

1 solution

Change Both Textbox's AllowDrop property value based on your list operation.

Ex: If you're gonna use Subject list, Disable AllowDrop for Company Textbox.
Ex: If you're gonna use Company list, Disable AllowDrop for Subject Textbox.

Once DragDrop over, Enable AllowDrop for both TextBoxes.
 
Share this answer
 
Comments
Member 13694735 5-Feb-22 12:23pm    
Could you please show with examples?
thatraja 6-Feb-22 7:36am    
It's like you have write txtCompany.AllowDrop = false inside lbxSubjects_MouseDown().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900