Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Clearing selected items from comboboxes

Clearing selected items from comboboxes

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rashar
    wrote on last edited by
    #1

    I have a combobox with 12 numbers listed in it. A user can either select a number, or type it in. I have a command button that will push the selected item into a local database. When I go back to the form, I still see the selected value. How can I have that selected item cleared once the data is saved to the database? I know i can use this: cboSelectedItem.text = "" However, if I have 50 comboboxes, that would be kind of tedius. All my textbox controls seems to clear the data fine, because I have it bound to a dataset so when I clear the dataset, the data in the textbox items clear as well. So I tried to have a collection of items on my combobox plus have it bound to a bindingsource, but Vb.net didn't like that either. Any advice is greatly appreciated. Rashar

    S 1 Reply Last reply
    0
    • R Rashar

      I have a combobox with 12 numbers listed in it. A user can either select a number, or type it in. I have a command button that will push the selected item into a local database. When I go back to the form, I still see the selected value. How can I have that selected item cleared once the data is saved to the database? I know i can use this: cboSelectedItem.text = "" However, if I have 50 comboboxes, that would be kind of tedius. All my textbox controls seems to clear the data fine, because I have it bound to a dataset so when I clear the dataset, the data in the textbox items clear as well. So I tried to have a collection of items on my combobox plus have it bound to a bindingsource, but Vb.net didn't like that either. Any advice is greatly appreciated. Rashar

      S Offline
      S Offline
      soodmonu
      wrote on last edited by
      #2

      i think one way you can follow is to define a variable as Controls....and then put a for loop for each variable in Controls.....then u can have a if statement or case statement inside which can filter all the Comboboxes and in that block u can clear the combobox.....and one thing is "Control is the base class for Buttons, ComboBox, Textbox etc. You may need to cast to appropriate type." this could be something like.... Dim ctr As Control For Each ctr In Controls If TypeOf (ctr) Is ComboBox Then CType(ctr, ComboBox).Items.Clear() End If Next like that it can clear all the comboboxes in that form. This could be one way. anyhow may be you have to format the code a bit, this is just an idea though

      R 1 Reply Last reply
      0
      • S soodmonu

        i think one way you can follow is to define a variable as Controls....and then put a for loop for each variable in Controls.....then u can have a if statement or case statement inside which can filter all the Comboboxes and in that block u can clear the combobox.....and one thing is "Control is the base class for Buttons, ComboBox, Textbox etc. You may need to cast to appropriate type." this could be something like.... Dim ctr As Control For Each ctr In Controls If TypeOf (ctr) Is ComboBox Then CType(ctr, ComboBox).Items.Clear() End If Next like that it can clear all the comboboxes in that form. This could be one way. anyhow may be you have to format the code a bit, this is just an idea though

        R Offline
        R Offline
        Rashar
        wrote on last edited by
        #3

        Ahhh... That worked nice. Thanks soodmonu!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups