Results 1 to 19 of 19

Thread: [RESOLVED] dont want any typing on combo box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Resolved [RESOLVED] dont want any typing on combo box

    hi all,

    how to set the combo box so that can't simply type anything inside it to avoid error occur when vb program is executing?

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: dont want any typing on combo box

    Set the Style property to 2-DropdownList
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: dont want any typing on combo box

    Style = 2-Dropdown List on combo1 property
    "More Heads are Better than One"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Re: dont want any typing on combo box

    when i set to style property to 2-dropdown list, the text in the combobox is combo1 and can't change anymore. i want change the text in combobox to 0. how?

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: dont want any typing on combo box

    Quote Originally Posted by mic_k86
    when i set to style property to 2-dropdown list, the text in the combobox is combo1 and can't change anymore. i want change the text in combobox to 0. how?
    At runtime it won't be combo1, but only one from the dropdown list or empty.

    If you don't want to permit blank also, just set the Combo1.ListIndex = 0 in your form_load, which will cause the first item in your dropdown list to be selected by default.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: dont want any typing on combo box

    Quote Originally Posted by mic_k86
    when i set to style property to 2-dropdown list, the text in the combobox is combo1 and can't change anymore. i want change the text in combobox to 0. how?
    this is an example:
    Code:
    Private Sub Form_Load()
    Dim i As Integer
    
    For i = 0 To 9
        Combo1.AddItem i
    Next i
    
    Combo1.ListIndex = 0
    
    End Sub
    "More Heads are Better than One"

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: dont want any typing on combo box

    Quote Originally Posted by mic_k86
    i want change the text in combobox
    When you do this
    Quote Originally Posted by Pradeep1210
    Set the Style property to 2-DropdownList
    you lose the ability to access the text property.

    If you need to access the text property, but not allow any one to physically type something in the text portion of the combo, then set the style back to its default of 0 - Dropdown Combo, and do this
    Code:
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
    End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Re: dont want any typing on combo box

    thanks everyone. my problem solved.

    one question:
    For i = 0 To 9
    if i want use 0, 10, 20, 30 in my combo box, how should i change it?

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: dont want any typing on combo box

    Well,
    Code:
    For i = 0 To 0
    makes no sense, so we can completely discount that.

    For the others, just set a variable, and use it
    Code:
    Dim x As Integer
    Dim i As Integer
    
    x = 10
    
    For i = 0 to x

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Re: dont want any typing on combo box

    hack, wat i mean is that i just have 4 variable 0, 10, 20, 30. how to do that? however, ur reply also give me more knowledge on this case.

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: dont want any typing on combo box

    Quote Originally Posted by Hack
    When you do this
    you lose the ability to access the text property.

    If you need to access the text property, but not allow any one to physically type something in the text portion of the combo, then set the style back to its default of 0 - Dropdown Combo, and do this
    Code:
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
    End Sub
    Won't the user be able to right click and paste something there defeating the purpose of this code?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  12. #12
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: dont want any typing on combo box

    Quote Originally Posted by mic_k86
    thanks everyone. my problem solved.

    one question:


    if i want use 0, 10, 20, 30 in my combo box, how should i change it?

    u mean like this?
    Code:
    For i = 0 To 30 Step 10
        Combo1.AddItem i
    Next i
    "More Heads are Better than One"

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Re: dont want any typing on combo box

    ya. jp. is like that. one more deep question, the coding is true only for variable which hv order, if o hv few variable like 1, 5, 8, 20, 60. how to change it?

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: dont want any typing on combo box

    Quote Originally Posted by mic_k86
    ya. jp. is like that. one more deep question, the coding is true only for variable which hv order, if o hv few variable like 1, 5, 8, 20, 60. how to change it?
    I think if you don't hve any consistancy between them, you can't just loop and add them. You will need to add them individually.

    Code:
    Combo1.AddItem 1
    Combo1.AddItem 5
    Combo1.AddItem 8
    Combo1.AddItem 20
    Combo1.AddItem 60
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: dont want any typing on combo box

    Quote Originally Posted by Pradeep1210
    Won't the user be able to right click and paste something there defeating the purpose of this code?
    Nope...setting KeyAscii = 0 also applies to CTRL+V

  16. #16
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: dont want any typing on combo box

    Quote Originally Posted by Pradeep1210
    I think if you don't hve any consistancy between them, you can't just loop and add them. You will need to add them individually.

    Code:
    Combo1.AddItem 1
    Combo1.AddItem 5
    Combo1.AddItem 8
    Combo1.AddItem 20
    Combo1.AddItem 60
    i agree.. hehehe
    "More Heads are Better than One"

  17. #17
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: dont want any typing on combo box

    Quote Originally Posted by Hack
    Nope...setting KeyAscii = 0 also applies to CTRL+V
    Errr... I meant clicking with the right mouse button and clicking Paste from the popup menu.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Posts
    172

    Re: dont want any typing on combo box

    ic. thank everyone.

  19. #19
    Lively Member wiz....'s Avatar
    Join Date
    Nov 2008
    Location
    Asia, Earth, Solar System, Milky Way Galaxy, Near Andromeda Galaxy, Universe
    Posts
    78

    Re: [RESOLVED] dont want any typing on combo box

    I have a very simple suggestion!!!!!!!!!!!!!!!! just set the LOCKED property of the combo box to TRUE !!!!! dat will do the trick.......but i guess dat wont allow u 2 select any other option.
    PAIN n SUFFERING-Pain is Inevitable,,suffering is optional...........
    WORK EXPECTATION--U can do anything in this world if u don't look for credit.........

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