Thread: how to create a drop down menu?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    how to create a drop down menu?

    Hi.
    I have some questions about drop down menu. will you plz help me?!

    1- Should I use a combo-box to create a drop down menu?
    if so, how can I make it some how readonly? I mean, I dont want the user to be able to write new things. For example, Just if he/she enters 'a' all of the items which start with 'a', appear.

    2- In a drop down menu the user can scroll the list by both mouse and arrow keys.
    I want to send the selected item to another function at the select time but I dont know which event to use?!
    By selected item I mean, the one which is clicked on while using mouse and the one which the user presses the enter key when he/she gets to it (while using arrow keys).

    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    Ps
    I am using visual studio 2005

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Yes, use a combobox, and set the DropDownStyle to DropDownList. Example:

    Code:
    this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

  4. #4
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    How about a context menu? I don't know if this is what you want, it's the menu where you right click somewhere and you get a menu. Through vs 2005 once you do that you can literally double click on the menu entry and get an event handler for that entry coded up for you. Then just do whatever you want with that menu selection.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    Quote Originally Posted by arian
    2- In a drop down menu the user can scroll the list by both mouse and arrow keys.
    I want to send the selected item to another function at the select time but I dont know which event to use?!
    By selected item I mean, the one which is clicked on while using mouse and the one which the user presses the enter key when he/she gets to it (while using arrow keys).
    I believe "SelectionChangeCommitted" is the event you want.

    Example:

    Code:
    comboBox1.SelectionChangeCommitted += new EventHandler(comboBox1_SelectionChangeCommitted);
    
    void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
    {
        MessageBox.Show(((ComboBox)sender).Text);
    }
    When you click on an item in the combo box, the "SelectionChangeCommitted" event is called, which in this case shows the item text in a messagebox.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    Thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. create menu with do while loop advice pls
    By ali_1 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2006, 09:34 PM
  3. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  4. Delet Frequency in linked list
    By swishiat.com in forum C Programming
    Replies: 16
    Last Post: 12-13-2003, 02:05 AM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM