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
  1. Home
  2. General Programming
  3. Visual Basic
  4. problem with combobox in tabcontrol

problem with combobox in tabcontrol

Scheduled Pinned Locked Moved Visual Basic
help
15 Posts 6 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.
  • L Luc Pattyn

    There are several approaches possible: 1. create a ComboBox array or collection (a generic list), copy a reference to each of the comboboxes in the list once (say in your form load handler), then do a foreach over that array every time you need to. 2. assuming there is only the one combobox on every tab page, execute the following pseudocode:

    foreach tabpage in tabcontrol
    foreach control in tabpage
    if control is combobox (skipping the other controls, e.g. buttons)
    do what needs to be done

    :)

    Luc Pattyn [Forum Guidelines] [My Articles]


    The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


    modified on Sunday, May 10, 2009 8:03 AM

    N Offline
    N Offline
    nazimghori
    wrote on last edited by
    #6

    hello i knew this approach but there are more than one combobox on each tabpage... so please suggest some other approach... :) :) :)

    L 1 Reply Last reply
    0
    • N nazimghori

      hello i knew this approach but there are more than one combobox on each tabpage... so please suggest some other approach... :) :) :)

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #7

      I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      N 3 Replies Last reply
      0
      • N nazimghori

        hi error is like operator '&' is not not defined for type 'system.windows.form.comboox' and integer seems to be syntax error but please suggest how to solve it... thank you in advance... :) :)

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #8

        Of course not. You're trying to build the name of a ComboBox in a string and then treating that string as if it was the combobox. That's not going to work. Luc has the best two solutions for you.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        modified on Sunday, May 10, 2009 9:46 PM

        1 Reply Last reply
        0
        • L Luc Pattyn

          I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          N Offline
          N Offline
          nazimghori
          wrote on last edited by
          #9

          hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..

          Sub fill(ByVal tbcon As TabControl)

              Dim cnt As Control
              For Each cnt In tbcon.Controls
          
                  If TypeOf cnt Is ComboBox Then
                      Select Case Tag
                          Case 0
                              cnt.Items.Add("NP")
                              cnt.Items.Add("ND")
                              cnt.Items.Add("FP")
                              cnt.Items.Add("FD")
                      End Select
                  End If
          
          
              Next
          End Sub
          

          but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....

          L D 2 Replies Last reply
          0
          • L Luc Pattyn

            I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            N Offline
            N Offline
            nazimghori
            wrote on last edited by
            #10

            hello i tried another alternative like

            dim cmbcntrl as combobox
            Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
            dim i as string
            For i = 0 To 11
            cmbcntrl = cmbcntrl.Items.AddRange(combos)
            next

            there are 11 comboxes and 11 tabpage each tabpage having 1 combobox now i name these comboboxes like combobox0,combobox1,combobox3.....and also there are other comboboxes in tabpages but they are with different name.. and tried above loop but still theres an error like:- 'expression doesnot produce a value..' so please suggest what shall i do.. thank you.... :) :) :)

            1 Reply Last reply
            0
            • L Luc Pattyn

              I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


              N Offline
              N Offline
              nazimghori
              wrote on last edited by
              #11

              hello i tried other approach like

              Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
              Dim i As Integer
              dim cmbcntrl as combobox
              For i = 0 To 11
              cmbcntrl = cmbcntrl.Items.AddRange(combos)

              i am having 11 comboboxes and 11 tabpages each having one combobox now i name these comboboxes like :combobox0,combobox1,combobox3....upto '11' and also there are other comboboxes in some tabpages but they are with different name.... now i tried above loop but it still states the syntax error like 'expression doesnot produces a value...' so please suggest what shall i do to solve it.. thank you.... :) :)

              A 1 Reply Last reply
              0
              • N nazimghori

                hello i tried other approach like

                Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
                Dim i As Integer
                dim cmbcntrl as combobox
                For i = 0 To 11
                cmbcntrl = cmbcntrl.Items.AddRange(combos)

                i am having 11 comboboxes and 11 tabpages each having one combobox now i name these comboboxes like :combobox0,combobox1,combobox3....upto '11' and also there are other comboboxes in some tabpages but they are with different name.... now i tried above loop but it still states the syntax error like 'expression doesnot produces a value...' so please suggest what shall i do to solve it.. thank you.... :) :)

                A Offline
                A Offline
                Andy_L_J
                wrote on last edited by
                #12

                Dim arr() As String = {"NP","ND","FP","FD",...}

                For Each tabPage In TabControl1
                For Each control In TabPage
                If control Is ComboBox Then
                control.Items.AddRange(arr)
                End If
                Next
                Next

                Surely this works

                I don't speak Idiot - please talk slowly and clearly I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury Driven to the arms of Heineken by the wife

                N 1 Reply Last reply
                0
                • A Andy_L_J

                  Dim arr() As String = {"NP","ND","FP","FD",...}

                  For Each tabPage In TabControl1
                  For Each control In TabPage
                  If control Is ComboBox Then
                  control.Items.AddRange(arr)
                  End If
                  Next
                  Next

                  Surely this works

                  I don't speak Idiot - please talk slowly and clearly I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury Driven to the arms of Heineken by the wife

                  N Offline
                  N Offline
                  nazimghori
                  wrote on last edited by
                  #13

                  hello the code suggested had an syntax error like 'tabpage is a type and cannot be used as an expression' so please suggest what shall i do to solve it.... :) :)

                  1 Reply Last reply
                  0
                  • N nazimghori

                    hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..

                    Sub fill(ByVal tbcon As TabControl)

                        Dim cnt As Control
                        For Each cnt In tbcon.Controls
                    
                            If TypeOf cnt Is ComboBox Then
                                Select Case Tag
                                    Case 0
                                        cnt.Items.Add("NP")
                                        cnt.Items.Add("ND")
                                        cnt.Items.Add("FP")
                                        cnt.Items.Add("FD")
                                End Select
                            End If
                    
                    
                        Next
                    End Sub
                    

                    but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #14

                    Of course your code does not compile: cnt is declared a Control, and Control does not have an Items property. You need to cast it to a ComboBox, something like Dim combo as ComboBox=DirectCast(cnt, ComboBox) :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                    1 Reply Last reply
                    0
                    • N nazimghori

                      hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..

                      Sub fill(ByVal tbcon As TabControl)

                          Dim cnt As Control
                          For Each cnt In tbcon.Controls
                      
                              If TypeOf cnt Is ComboBox Then
                                  Select Case Tag
                                      Case 0
                                          cnt.Items.Add("NP")
                                          cnt.Items.Add("ND")
                                          cnt.Items.Add("FP")
                                          cnt.Items.Add("FD")
                                  End Select
                              End If
                      
                      
                          Next
                      End Sub
                      

                      but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....

                      D Offline
                      D Offline
                      DidiKunz
                      wrote on last edited by
                      #15

                      ..it should read somthiing like:

                      Sub fill(ByVal tbcon As TabControl)
                          Dim cnt As Control
                          For Each cnt In tbcon.Controls
                              If TypeOf cnt Is ComboBox Then
                                  Select Case **CType(cnt, ComboBox).Tag**
                                      Case 0
                                          cnt.Items.Add("NP")
                                          cnt.Items.Add("ND")
                                          cnt.Items.Add("FP")
                                          cnt.Items.Add("FD")
                                  End Select
                              End If
                          Next
                      End Sub
                      

                      Otherways the compiler doesn't know 'Tag' Regards: Didi

                      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