Link to home
Start Free TrialLog in
Avatar of 1eEurope
1eEuropeFlag for Switzerland

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));
}

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

it most likely has something to do with not being over the checkbox when the mouse button is released. can't you just manually check the box within your mousedown event?

checkbox.checked = true;
Avatar of 1eEurope

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial