By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

Help with _DragDrop on listbox?

P: n/a
Subject: Help with DoDragDrop event?
From: Alex <me******@test.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Hi all,

I'm having a problem with drag/drop on listboxes... basically I created
a user control that is used to create many listboxes on the form
dynamically at runtime. Each of these is assigned a unique value for
employee.

When an item is dragged from one listbox to another, a row in the db is
updated to reflect the employee change and the listboxes then refresh
from the db & the item is shown in the dragged to listbox.

The problem I'm having is that on a single click on an item, the update
and refresh are happening. I'd like to supress this action in the case
of a simple selection versus doing it when a drag to another listbox is
actually done.

Here's some code:

I'm trying to find the employee from the dragfrom listbox and compare it
to the employee on the dragto listbox in order to supress the action, but
when I access it via the 'sender' object in _DragDrop, I get the employee
on the dragto listbox.

This does work when I don't have that conditional in there, but I get
extra updates and refreshes every time I single click.

Should the sender object in _DragDrop reference the object that I dragged
from?

Thanks!
private void listBoxTeamMember_DragEnter(object sender,
DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text)) //replace with
listbox row type
{
e.Effect = DragDropEffects.Move;
}
}
private void listBoxTeamMember_DragDrop(object sender,
DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
//do it and refresh

int iDragFromEmpSKey;
iDragFromEmpSKey = Convert.ToInt32
(((System.Data.DataRowView)(((System.Windows.Forms .ListBox)
(sender)).SelectedItem))["AssignedEmployeeSKey"]);
//don't dragdrop within the same listbox
if (! (iDragFromEmpSKey == EmployeeSKey ))
{

DMG.AssignmentDraggedToEmployee
(e.Data.GetData(DataFormats.Text).ToString(),

EmployeeSKey, EmployeeUnitID);
//refresh window to show changes
ptr_RefreshFromTeamSelection.DynamicInvoke(null);
}
}
}
private void listBoxTeamMember_MouseDown(object sender,
MouseEventArgs e)
{

if (MouseButtons == MouseButtons.Left)
{
listBoxTeamMember.DoDragDrop(((DataRowView)
listBoxTeamMember.SelectedItem)["AssignmentSKey"].ToString(),
DragDropEffects.Move);
}
}

Dec 1 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.