Hi,
What i want to tried to create is a continuous form (Like Access). So i can display the data in a way i want.
I'm trying for 1 1/2 day getting it to work.
I have some succes in creating some sort of continuos form
I put a panel in a form and placed in the panel the requerd labels, textbox and button.
The text property of the textbox and labels i used to reference a table field so i can fill it with the data from a table
I loop through the data and add for every row the set of controls.
schematic layout of the controls
[label1] [label2 ] [Texbox ] [Button]
[label3 ] [ ]
[ ]
Here is the code i use (oke you can start laughing now)
Oke when you finished laughing please read on.
I know it not pretty and yes i can be done better (A lot better i think)
There is only one thing I can't do and that is to compleetly duplicate the properties of the fields.
I use a multiline textbox, but that property is not set when it is duplicated.
So here is my question (At last):
Can someone show me how to do this properly.
What i want to tried to create is a continuous form (Like Access). So i can display the data in a way i want.
I'm trying for 1 1/2 day getting it to work.
I have some succes in creating some sort of continuos form
I put a panel in a form and placed in the panel the requerd labels, textbox and button.
The text property of the textbox and labels i used to reference a table field so i can fill it with the data from a table
I loop through the data and add for every row the set of controls.
schematic layout of the controls
[label1] [label2 ] [Texbox ] [Button]
[label3 ] [ ]
[ ]
Here is the code i use (oke you can start laughing now)
Code:
'Array voor opslaan gegevens velden
Dim veldType(20) As String
Dim veldBackColor(20) As Color
Dim veldForeColor(20) As Color
Dim veldFont(20) As Font
Dim veldLocationX(20) As Integer
Dim veldLocationY(20) As Integer
Dim veldName(20) As String
Dim veldSize(20) As Size
Dim veldText(20) As String
Dim veldAlign(20) As ContentAlignment
Dim veldEnabled(20) As Boolean
Dim veldVisible(20) As Boolean
Dim veldControl As ControlCollection
Dim varAantalVelden As Single = 0
Private Sub FrmTRA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsRegels As New DataSet
Dim varOphogen As Integer = 0
'**** Gegevens van de controls opslaan ****
Try
Dim varControl As Control
Dim I As Single
Dim naam As String
For Each varControl In pnlRisicoBepalingen.Controls
'Gegevens van het veld opslaan in het geheugen
veldType(varAantalVelden) = varcontrol.GetType.Name
veldBackColor(varAantalVelden) = varcontrol.BackColor
veldForeColor(varAantalVelden) = varcontrol.ForeColor
veldFont(varAantalVelden) = varcontrol.Font
veldLocationX(varAantalVelden) = varcontrol.Location.X
veldLocationY(varAantalVelden) = varcontrol.Location.Y
veldName(varAantalVelden) = varcontrol.Name
veldSize(varAantalVelden) = varcontrol.Size
veldText(varAantalVelden) = varcontrol.Text
veldEnabled(varAantalVelden) = varcontrol.Enabled
veldVisible(varAantalVelden) = varcontrol.Visible
'Controle of dit het laagst geplaatste veld is, zo ja dan wordt dit gegeven opgeslagen
If varControl.Top > varOphogen Then
'gegeven opslaan
varOphogen = varControl.Top
End If
'Aantal velden met 1 ophogen
varAantalVelden += 1
Next
varOphogen += 10
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Probleem opslaan velden")
End Try
'**** Ophalen van de gegevens ****
Try
Dim varSQL As String = "SELECT Tbl_TRA_Sub.IDtra, Tbl_TRA_Sub.IDtra_Sub, Tbl_TRA_Klasse.Klasse_Nummer, Tbl_TRA_Klasse.Klasse_Omschrijving, Tbl_TRA_Klasse_Sub.Klasse_Sub_Omschrijving, Tbl_TRA_Sub.Maatregel " & _
"FROM Tbl_TRA_Klasse_Sub INNER JOIN Tbl_TRA_Sub ON Tbl_TRA_Klasse_Sub.IDKlasse_Sub = Tbl_TRA_Sub.IDKlasse_Sub INNER JOIN " & _
"Tbl_TRA_Klasse ON Tbl_TRA_Sub.IDKlasse = Tbl_TRA_Klasse.IDklasse"
Dim Gegevens As New SqlDataAdapter(varSQL, SQLConnection)
Gegevens.Fill(dsRegels, "Regels")
Gegevens.Dispose()
Gegevens = Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Probleem ophalen gegevens")
End Try
'**** Nieuwe velden aanmaken
Try
Dim varRegels As Integer
Dim varControl As Control
Dim I As Integer
'Controleren of er gegevens beschikbaar zijn
If dsRegels.Tables("Regels").Rows.Count > 0 Then
'Door alle regels heen lopen
For varRegels = 0 To dsRegels.Tables("Regels").Rows.Count - 1
'Indien het de eerste regel is dan worden de reeds geplaatste velden gevuld met gegevens
If varRegels = 0 Then
'Langs alle velden lopen
For Each varcontrol In pnlRisicoBepalingen.Controls
'Controleren of het om een label of tekstveld gaat
Select Case varcontrol.GetType.Name
Case "Label", "TextBox"
'Controleren of er een veldnaam is opgegeven
If Not IsDBNull(varcontrol.Text) And varcontrol.Text <> "" Then
'Gegevens van tabel invullen
varcontrol.Text = Convert.ToString(dsRegels.Tables("regels").Rows(varRegels).Item(varcontrol.Text))
End If
End Select
Next
Else
For I = 0 To varAantalVelden - 1
Select Case veldType(i)
Case "Label"
Dim varVeld As New Label
With varVeld
.BackColor = veldBackColor(i)
.ForeColor = veldForeColor(i)
.Font = veldFont(i)
.Location = New System.Drawing.Point(veldLocationX(i), veldLocationY(i) + (varRegels * varOphogen))
.Name = veldName(i) & varRegels
.Size = veldSize(i)
If veldText(i) <> "" And Not IsDBNull(veldText(i)) Then
.Text = Convert.ToString(dsRegels.Tables("regels").Rows(varRegels).Item(veldText(i)))
End If
Me.pnlRisicoBepalingen.Controls.Add(varVeld)
End With
Case "TextBox"
Dim varVeld As New TextBox
With varVeld
.BackColor = veldBackColor(i)
.ForeColor = veldForeColor(i)
.Font = veldFont(i)
.Location = New System.Drawing.Point(veldLocationX(i), veldLocationY(i) + (varRegels * varOphogen))
.Name = veldName(i) & varRegels
.Size = veldSize(i)
If veldText(i) <> "" And Not IsDBNull(veldText(i)) Then
.Text = Convert.ToString(dsRegels.Tables("regels").Rows(varRegels).Item(veldText(i)))
End If
Me.pnlRisicoBepalingen.Controls.Add(varVeld)
End With
Case "Button"
Dim varVeld As New Button
With varVeld
.BackColor = veldBackColor(i)
.ForeColor = veldForeColor(i)
.Font = veldFont(i)
.Location = New System.Drawing.Point(veldLocationX(i), veldLocationY(i) + (varRegels * varOphogen))
.Name = veldName(i) & varRegels
.Size = veldSize(i)
.Text = veldText(i)
Me.pnlRisicoBepalingen.Controls.Add(varVeld)
End With
End Select
Next
End If
Next
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Probleem met aanmaken velden")
End Try
End Sub
Oke when you finished laughing please read on.
I know it not pretty and yes i can be done better (A lot better i think)
There is only one thing I can't do and that is to compleetly duplicate the properties of the fields.
I use a multiline textbox, but that property is not set when it is duplicated.
So here is my question (At last):
Can someone show me how to do this properly.