4 Replies - 583 Views - Last Post: 19 March 2012 - 05:59 PM Rate Topic: -----

#1 meowbits  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 107
  • Joined: 31-January 12

How to handle controls made at runtime

Posted 19 March 2012 - 03:51 PM

If I have the following code, which adds combobox's to a tableControlPanel.
How do I handle the index changing in the combobox?
The second code shows what I am trying to do, except for multiple combobox's that are made on runtime.


For i As Integer = 0 To weightClass.GetUpperBound(0)
                Dim player As New ComboBox
                Dim playerPosition As New TableLayoutPanelCellPosition(1, i)

                player.Name = "PlayerComboBox_" & i
                player.Size = New System.Drawing.Size(240, 40)

                cmd.CommandText = "SELECT FIRSTNAME, LASTNAME FROM MY_TEAM WHERE WEIGHT = " & weightClass(i)
                myReader = cmd.ExecuteReader
                Do While myReader.Read()
                    player.Items.Add(myReader("LASTNAME") & ", " & myReader("FIRSTNAME"))
                Loop
                TableLayoutPanel1.SetCellPosition(player, playerPosition)
                TableLayoutPanel1.Controls.Add(player)
            Next


    Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        loadPlayerdata()
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: How to handle controls made at runtime

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: How to handle controls made at runtime

Posted 19 March 2012 - 04:13 PM

All controls are made at runtime.
Was This Post Helpful? 0
  • +
  • -

#3 meowbits  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 107
  • Joined: 31-January 12

Re: How to handle controls made at runtime

Posted 19 March 2012 - 04:46 PM

How to handle them when they are not visually on the form until run time then...
Was This Post Helpful? 0
  • +
  • -

#4 shadachi  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 25-January 08

Re: How to handle controls made at runtime

Posted 19 March 2012 - 04:59 PM

You Assign Handlers when creating them dynamically ..

Here is a link to the tutorial Click Here
Was This Post Helpful? 1
  • +
  • -

#5 meowbits  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 107
  • Joined: 31-January 12

Re: How to handle controls made at runtime

Posted 19 March 2012 - 05:59 PM

Thanks,

I have a new question.

How do I find out the index of whichever combobox has the selectedIndexChanged?

This post has been edited by meowbits: 19 March 2012 - 06:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1