2016-12-03 59 views
0
到GridView控件

請幫我 我想,當點擊使用數據表按鈕來進入添加新行,我用這個子添加新行按鈕使用數據表Vb.NET

在我使用的頂部私人醫生爲數據行= dt.newrow(),私人DT的數據表,名次爲整數

Private Sub AddDataTable 
    User = txtUser.Text 
    Password = txtPass.Text 
    Address = txtAddress.Text 

    'add Row... 
    dr(0) = User 
    dr(1) = Password 
    dr(2) = Address 
    'dt.Rows.Add(dr) 
    dt.Rows.InsertAt(dr, Pos) 
    Pos = Pos + 1 
End Sub 

爲了獲取事件單擊

Private Sub btGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btGet.Click 
     dgvUser.DataSource = dt 
    End Sub 

,最後一個添加事件點擊

Private Sub btAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAdd.Click 
     AddDataTable() 
     txtUser.Clear() 
     txtPass.Clear() 
     txtAddress.Clear() 
    End Sub 

結果始終是1行,當我嘗試重新添加一個新行它給我一個錯誤

回答

0

insode的AddDataTable方法來創建新行,並在年底

Private Sub AddDataTable 
    Dim dr1 As DataRow = dt.NewRow 
    User = txtUser.Text 
    Password = txtPass.Text 
    Address = txtAddress.Text 

    'add Row... 
    dr1 (0) = User 
    dr1 (1) = Password 
    dr1 (2) = Address 
    dgvUser.DataSource = dt; 
End Sub 
設置datasouce
+0

它給我錯誤此行已屬於此表 – Shiroze

+0

感謝它的作品。 – Shiroze

相關問題