Drag Drop stops in the middle of the code. Weird.

aewarnick

Senior Contributor
Joined
Jan 29, 2003
Messages
1,031
C#:
private void listBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
	Drop(e);
}

void Drop(DragEventArgs e)
{
           this.listBox1.SelectedIndexChanged -= new System.EventHandler(this.listBox1_SelectedIndexChanged);
this.timer.Enabled=false;
	string[]oldV=new String[this.listBox1.Items.Count];
for(int i=0; i < oldV.Length; i++)
{
	oldV[i]= i+1+"";
}
string[]newV=new String[this.listBox1.Items.Count];
for(int i=DragIndex; i >= 0; i--)
{
//MessageBox.Show(i+"  --"+(this.selIndex+1));
if(i==DragIndex)
	newV[i]= this.selIndex+1+"";
else
	newV[i]= i+1+"";
}
for(int i=DragIndex; i <= newV.Length-DragIndex+1; i++)
{
                //MessageBox.Show(i+"  ++"+(this.selIndex+1));
                if(i==DragIndex)
	newV[i]= this.selIndex+1+"";
	else
	newV[i]= i+1+"";
}


/*THIS IS WHERE THE CODE STOPS*/


bool ok= a.registry.RenameRegValues(ref ImageKey, oldV, newV);
if(!ok) MessageBox.Show("not ok");
	this.listBox1.Items.Remove(this.listBox1.Items[selIndex]);
string[] s= (string[])e.Data.GetData(typeof(string[]));
this.listBox1.Items.Insert(DragIndex, s[0]);
this.timer.Enabled=true;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
}
I tried sending the method a whole new DragEventArgs but the same thing occured. I tried putting the bottom half of the code at the top. It executed and the rest did not. It probably stopped at the same spot as before.

Is this normal? Is there a way around it?
 
I modified the code some and it works every time now. I still do not know why. There must have been an error in the code somewhere that was being caught without giving an error message.
 
Back
Top