benshaws
Hobbyist Programmer
Hi,
I had a panel with buttons on. I need to loop through the buttons and apply settings from a database. This I can do with the one panel.
I now have three panel's. I can do the same by repeating the code for the first panel in another two code blocks. However, this does not seem to be the way it should be done.
I have tried a few things in line 7 above, such as
But I can't seem to work out the correct syntax. Maybe, I am coming at this wrong - I don't know.
Thanks for looking.
I had a panel with buttons on. I need to loop through the buttons and apply settings from a database. This I can do with the one panel.
I now have three panel's. I can do the same by repeating the code for the first panel in another two code blocks. However, this does not seem to be the way it should be done.
VB.NET:
'Read the EPOS buttons from the settings database and apply to the set EPOS buttons.
Dim ds As New DataSet
Dim strQuery As String = "SELECT BUTTONID, LABEL, DESCRIPTION, COLOUR FROM SALESBUTTONS"
FillDataSet(ds, strQuery, "SALESBUTTONS")
'Apply each setting to each button.
For Each Btn As Button In Panel1.Controls.OfType(Of Button)()
For Each dr As DataRow In ds.Tables(0).Rows
If dr.Item(0) = Btn.Name Then
If dr.Item(2).ToString = String.Empty Then
Btn.Enabled = False
Btn.Visible = False
Else
Btn.Enabled = True
Btn.Visible = True
End If
End If
Next
Next
I have tried a few things in line 7 above, such as
VB.NET:
For Each Btn As Button In Panel1.Controls.OfType(Of Button)() And In Panel2.Controls.OfType(Of Button)()
'etc
Next
But I can't seem to work out the correct syntax. Maybe, I am coming at this wrong - I don't know.
Thanks for looking.