2014-01-21 113 views
-1

我真的不知道如何編碼流程。從數據庫中加載動態保存的按鈕

For Each dtrow In camBtnDtable.Rows 
    Dim cameraNumber = camBtnDtable.Select("ButtonName =" & " '" & "foo" & "'")(0)("cameraID") 
    Dim nBtn As New Button 

    nBtn.Text = "C-" & 'this should be cameraNumber e.g "C-01" 
    nBtn.Name = 'select from the database, I don't know if this is still important though 
    nBtn.Location = 'select x and y from database where name is this 

    AddHandler nBtn.Click, AddressOf nBtn_Click 

    picture.Controls.Add(nBtn) 
Next 

這是一個混亂的代碼,但是,一般來說,我想要的是從訪問數據庫加載按鈕的屬性。

回答

1
Dim Btn as Button 

' assumes the camBtnDtable is something Like Select * from buttons 
For Each dtRow in camBtnDtable.Rows 
    Btn = New Button 

    Btn.Name = dtRow.CameraButtonNameColumn 
    Btn.Text = dtRow.CameraButtonTextColumn 
    Btn.Location = dtRow.CameraButtonLocationColumn 
    ' or 
    Btn.Location = New Point(dtRow.CameraButtonXColumn, 
          dtRow.CameraButtonYColumn) 

    picture.Controls.Add(Btn) ' ??? picture? not form? 

    AddHandler nBtn.Click, AddressOf nBtn_Click 
Next 
  1. 沒有列名的想法
  2. 沒有了DB模式
  3. 不知道你已經保存按鈕(即位置VS X,Y)
  4. 沒有想到的主意爲什麼你解析名稱,道具應該按原樣存儲並且不需要處理就恢復

單個行將有一個按鈕的所有數據,所以只需循環thr你的行。

+0

序列化代碼中的'btn'包含了什麼? – AdorableVB

+0

這是一個錯誤 - 它將成爲更長的答案的一部分,但我並沒有全部刪除它 – Plutonix

+0

我認爲我太過分了。這是一個簡單的答案。我的錯。無論如何謝謝你總是幫助我。 – AdorableVB

相關問題