Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Dynamic Button Controls

Status
Not open for further replies.

mariuslaurentiu

Programmer
May 31, 2005
10
0
0
RO
I am writing an application that requires button controls to be created at runtime because the amoutn of controls created depends on data retrieved from a database.


Do While (SQLreader.Read())
EtichetaControl = SQLreader4("EtichetaControl").ToString()
TipControl = SQLreader4("TipControl").ToString()
ColtStanga = SQLreader4("ColtStanga").ToString()
ColtSus = SQLreader4("ColtSus").ToString()
InaltimeForma = SQLreader4("InaltimeForma").ToString()
LatimeForma = SQLreader4("LatimeForma").ToString()
ColtStangaForma = SQLreader4("ColtStangaForma").ToString()
ColtSusForma = SQLreader4("ColtSusForma").ToString()
LungimeControl = SQLreader4("LungimeControl").ToString()
ProceduraApelata = SQLreader4("ProceduraApelata").ToString()
ControlId = SQLreader4("ControlId").ToString()

Dim TempButton As New Button()
TempButton.Name = "TempButton" & CStr(ControlId)
TempButton.Text = EtichetaControl
TempButton.Top = ColtSus
TempButton.Left = ColtStanga
TempButton.Width = LungimeControl
AddHandler TempButton.Click, AddressOf Executie
Loop

Private Sub Executie(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TypeOf sender Is Button Then
' when i press the button i wish to execute stored procedure ProceduraApelata
End If
End Sub





 

I'm not really sure what your question is here. I do notice that you haven't actually added the buttons to your form. Try doing this:

Do While (SQLreader.Read())
EtichetaControl = SQLreader4("EtichetaControl").ToString()
TipControl = SQLreader4("TipControl").ToString()
ColtStanga = SQLreader4("ColtStanga").ToString()
ColtSus = SQLreader4("ColtSus").ToString()
InaltimeForma = SQLreader4("InaltimeForma").ToString()
LatimeForma = SQLreader4("LatimeForma").ToString()
ColtStangaForma = SQLreader4("ColtStangaForma").ToString()
ColtSusForma = SQLreader4("ColtSusForma").ToString()
LungimeControl = SQLreader4("LungimeControl").ToString()
ProceduraApelata = SQLreader4("ProceduraApelata").ToString()
ControlId = SQLreader4("ControlId").ToString()

Dim TempButton As New Button()
TempButton.Name = "TempButton" & CStr(ControlId)
TempButton.Text = EtichetaControl
TempButton.Top = ColtSus
TempButton.Left = ColtStanga
TempButton.Width = LungimeControl
AddHandler TempButton.Click, AddressOf Executie
[red]Me.Controls.Add(TempButton)[/red]
Loop

Private Sub Executie(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TypeOf sender Is Button Then
' when i press the button i wish to execute stored procedure ProceduraApelata
End If
End Sub




If that is not what you needed, please post more information.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top