我正在尝试重用一个为数据库中的每个项目创建按钮的过程。我在我的程序中使用完全相同的程序大约6次,所以我想找到一种方法,我只需编写一次并重复使用。
我的问题是,由于我将使用不同的数据表和表适配器,我如何参数化这些2?
我弄明白了其余的参数:按钮,标签和表格。这是我的代码
Public Sub addCategories()
'Procedure creates a button for each category
'stored in the database and adds them to the
'main panel
Dim ta As New ContactsAndInventoryDataSetTableAdapters.PRODUCT_CATEGORYTableAdapter
Dim dt As DataTable = ta.GetData
For Each row As DataRow In dt.Rows
Dim btn As New btnCategoryTabs()
btn.lblCategoryName.Name = DirectCast(row("Category_Name"), String)
btn.lblCategoryName.Text = btn.lblCategoryName.Name
btn.lblCategoryID.Text = CStr(row("Category_ID"))
Using STREAM As New MemoryStream(DirectCast(row("image"), Byte()))
btn.picPCategoryPicture.Image = Image.FromStream(STREAM)
End Using
'Add categories to the Panel
frmManageStore.flpMainPanel.Controls.Add(btn)
Next
End Sub