views:

312

answers:

2

I'm trying to have a Windows Forms ContextMenuStrip control display a list of countries, about 200 total. Currently it displays them all vertically which creates for a long wait time to scroll to countries near the bottom of the list. I've tried messing with the ContextMenuStrip.LayoutStyle property but it hasn't gotten me anywhere. Might anyone have any tips for this? I've also search google but haven't found the answer. Thanks for any help!

A: 

This isn't really a code related answer, but have you thought about grouping the countries by continent and displaying it in a submenu? That way the user would probably be able to get to the country they wanted faster. If not by continent, then perhaps another grouping would be more appropriate?

Joseph
Thought about it - but, the business requirements aren't asking for that. They want a full alphabetical list. If there is not a way, then we may have to go the route you suggested.
bbqchickenrobot
How about grouping them alphabetically? A-F G-P etc?
Joseph
A: 

I don't know of a way to use a mouse roller or page down with a context menu. Instead of a contextMenuStrip you could open a form containing a docked listbox with the 200 countries in it, and return the selection via global or public variable. Formborderstyle = none will get rid of the title bar. You can use events other than doubleclick if you want it to more closely mimick the context menu user interface.

Public Class Form1
  Public selectedCountry As String
  Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Right Then Form2.ShowDialog()
  End Sub
End Class

Public Class Form2
  Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    Form1.selectedCountry = ListBox1.SelectedItem
    Me.Close()
  End Sub
End Class
xpda