Results 1 to 4 of 4

Thread: [3.0/LINQ] Double Click Listbox

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    [3.0/LINQ] Double Click Listbox

    Hi, im trying to make a listbox Selects it items when the users doubleclicks over the item, but so far i cant get it done, can someone tell me how to do this ??

    thanks

    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [3.0/LINQ] Double Click Listbox

    I hope i don't misunderstand your question, but is it that you're displaying items in a listbox and when the user clicks on an item, select and display the item that was selected? If so then:

    Let's say we have a listbox named lst1

    Code:
    // add some items to listbox lst1
    
                lst1.Items.Add("monday");
                lst1.Items.Add("tuesday");
                lst1.Items.Add("wednesday");
                lst1.Items.Add("friday");  
    
    The event handler behind the list box:
    
            private void lst1_SelectedIndexChanged(object sender, EventArgs e)
            {
                MessageBox.Show(lst1.SelectedItem.ToString());
    
            }
    Jennifer.

  3. #3

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [3.0/LINQ] Double Click Listbox

    I want that to happend when the user double clicks the Item,
    C# and WPF developer
    My Website:
    http://singlebits.com/

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [3.0/LINQ] Double Click Listbox

    CSharp Code:
    1. private void ListBox1_MouseDoubleClick(object sender, MouseEventArgs e)
    2. {
    3.     if(this.ListBox1.IndexFromPoint(e.Location) != ListBox.NoMatches)
    4.     {
    5.         MessageBox.Show(this.ListBox1.GetItemText(this.ListBox1.SelectedItem));
    6.     }
    7. }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width