How to call the default handler?
-
I have a problem. I have a Mouse-down handler for a list box. The problem is that the list box's selected item wont change till my handler has exited. Lets say the list box contains two items ---------- |apple | |orange | <- selected ---------- Now if I click on apple and do a :- MessageBox.Show(listbox.SelectedItem.ToString()) I still get orange. Next time I click I get apple. What happens is that my handler gets called and only afterwards does the real handler gets called which changes the selected item index. Now how do call the default handler something like calling the base class handler Regards Nish :confused:
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
-
I have a problem. I have a Mouse-down handler for a list box. The problem is that the list box's selected item wont change till my handler has exited. Lets say the list box contains two items ---------- |apple | |orange | <- selected ---------- Now if I click on apple and do a :- MessageBox.Show(listbox.SelectedItem.ToString()) I still get orange. Next time I click I get apple. What happens is that my handler gets called and only afterwards does the real handler gets called which changes the selected item index. Now how do call the default handler something like calling the base class handler Regards Nish :confused:
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
Why are you using MouseDown? Why not just use click? The problem with MouseDown is that a "click" hasnt happened until the mouse has been released, ie, MouseUp. To illustrate, if you hold your mouse down on a list box and move the mouse up and down, the selection will change. Thus lifting the mousebutton "locks in" the item that is selected. Having said all of that, there may in fact be a way, i havent tried :p -- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
-
Why are you using MouseDown? Why not just use click? The problem with MouseDown is that a "click" hasnt happened until the mouse has been released, ie, MouseUp. To illustrate, if you hold your mouse down on a list box and move the mouse up and down, the selection will change. Thus lifting the mousebutton "locks in" the item that is selected. Having said all of that, there may in fact be a way, i havent tried :p -- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
I need to use MouseDown as I am doing some drag/drop stuff Nish
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
-
I need to use MouseDown as I am doing some drag/drop stuff Nish
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
You could always just use a simple hit-test to find out the item under the cursor. Assuming all of the items are the same height (ie, not OwnerDrawVariable) you could use :
private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int iItem = (e.Y / listBox1.ItemHeight) + listBox1.TopIndex;
if (iItem > listBox1.Items.Count - 1)
{
lblCount.Text = "none";
}
else
{
lblCount.Text = listBox1.Items[iItem].ToString();
}
}-- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
-
You could always just use a simple hit-test to find out the item under the cursor. Assuming all of the items are the same height (ie, not OwnerDrawVariable) you could use :
private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int iItem = (e.Y / listBox1.ItemHeight) + listBox1.TopIndex;
if (iItem > listBox1.Items.Count - 1)
{
lblCount.Text = "none";
}
else
{
lblCount.Text = listBox1.Items[iItem].ToString();
}
}-- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
Thanks David But James Johnson suggested another solution to me :- IndexFromPoint Nish :-)
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
-
Thanks David But James Johnson suggested another solution to me :- IndexFromPoint Nish :-)
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice
Nish [BusterBoy] wrote: IndexFromPoint ROFL... that exists? Thats about my luck these days :-D -- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
-
Nish [BusterBoy] wrote: IndexFromPoint ROFL... that exists? Thats about my luck these days :-D -- David Wengier TAC ad gone wrong: "Don't fool yourself, you're a bloody idiot." Sonork ID: 100.14177 - Ch00k
David Wengier wrote: ROFL... that exists? Thats about my luck these days :-) Nish
Oh, I don't know why she's leaving, or where she's gonna go I guess she's got her reasons but I just don't wanna know 'Cos for 24 years I've been living next door to Alice 24 years just waitin' for a chance To tell her how I feel and maybe get a second glance Now I gotta get used to not living next door to Alice