Can ComboBox be setted as readonly?

Discussion in 'Questions (Windows Mobile)' started by blackiice, Oct 24, 2007.

  1. blackiice

    blackiice Member

    I need a readonly ComboBox(user can select items,but can not edit or del the word),is it possible?
  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

  3. agraham

    agraham Expert Licensed User

    Yes but it is a bit messy as you can type into the ComboBox and doing so resets SelectedIndex.

    However (he said with an appropriate flourish!) with my ControlEvents library and an undocumented Text property of the ComboBox

    Sub Globals
    'Declare the global variables here.   
       CB1index = -1
    End Sub

    Sub App_Start
    End Sub

    Sub ComboBox1_SelectionChanged(I, v)
        CB1index = ComboBox1.SelectedIndex
    End Sub

    Sub CbEvents_TextChanged
    If CB1Index >= 0 Then ' AND ComboBox1.SelectedIndex = -1  Then
          ' the user has typed into a selection and so unset SelectedIndex so reset it
          ComboBox1.SelectedIndex = CB1index
          ComboBox1.Text = ComboBox1.Item(ComboBox1.SelectedIndex)
    ' the useR is trying to type into the empty combobox - don't let him!
          ComboBox1.Text = ""
    End If
    End Sub
  4. specci48

    specci48 Well-Known Member Licensed User

    Everyone should remember that the combobox has a different behaviour on the desktop and on the device.
    - on the desktop, you are able to write free text into a combobox so that the selectedIndex returns -1
    - on the device, it is not possible to "edit" the combobox

    This seems to be a difference between .Net and .Net CF.

  5. blackiice

    blackiice Member

    It's a good idea, Thanks a lot.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice