Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to call the default handler?

How to call the default handler?

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • N Nish Nishant

      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

      D Offline
      D Offline
      David Wengier
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • D David Wengier

        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

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • N Nish Nishant

          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

          D Offline
          D Offline
          David Wengier
          wrote on last edited by
          #4

          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

          N 1 Reply Last reply
          0
          • D David Wengier

            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

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • N Nish Nishant

              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

              D Offline
              D Offline
              David Wengier
              wrote on last edited by
              #6

              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

              N 1 Reply Last reply
              0
              • D David Wengier

                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

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups