1eEurope
asked on
mousedown cancels checkonclick
i've got a checkedlistbox with a mousedown event which starts a dragNdrop procedure. one can move entries up and down in the list. unfortunatly this event cancels the checkonclick property of the list. even if i write a mouseclick event for checking the boxes it doesn't work, the event just ins't triggered. what am i doing wrong?
private void lbx_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (((CheckedListBox)sender).Items.Count == 0)
return;
int index = ((CheckedListBox)sender).IndexFromPoint(e.X, e.Y);
//set to last entry
if (index == -1)
return;
Sp sp = (Sp)((CheckedListBox)sender).Items[index];
DragDropEffects dde1 = DoDragDrop(sp, DragDropEffects.Move);
}
private void lbx_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void lbx_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
Sp sp = (Sp) e.Data.GetData(typeof (Sp));
int indexPos = ((CheckedListBox) sender).IndexFromPoint(((CheckedListBox) sender).PointToClient(new Point(e.X, e.Y)));
((CheckedListBox) sender).Items.Remove(sp);
if (indexPos > -1)
((CheckedListBox) sender).Items.Insert(indexPos, sp);
else
((CheckedListBox) sender).Items.Add(sp);
}
private void lbx_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
int index = ((CheckedListBox)sender).IndexFromPoint(e.X, e.Y);
((CheckedListBox)sender).SetItemChecked(index, !((CheckedListBox)sender).GetItemChecked(index));
}
ASKER
i can't do it in the mousedown event because if you just want to move it, it shouldn't be ckecked automaticly. i can uncheck them without any problems regardles if i'm above the checkbox or not.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
checkbox.checked = true;