[英]VB.NET Pass values from textbox to datagridview
I want to pass values of textboxes to a datagridview using below code. 我想使用以下代码将文本框的值传递给datagridview。
Private Sub txtDrCr_Leave(sender As Object, e As System.EventArgs) Handles txtDrCr.Leave
Dim nR As Integer
nR = TxtList.Rows.Add()
TxtList.Item("stsno", nR).Value = nR + 1
TxtList.Item("stAcctCode", nR).Value = txtAccountCode.Text
TxtList.Item("stAcctName", nR).Value = txtAccountName.Text
TxtList.Item("stBranch", nR).Value = txtBranchName.Text
TxtList.Item("stDescription", nR).Value = txtDescription.Text
TxtList.Item("stAmount", nR).Value = txtAmount.Text
TxtList.Item("stDrCR", nR).Value = txtDrCr.Text
cleartextboxes()
End Sub
This code add two lines in the gridview whenever I leave the txtDRCR. 每当我离开txtDRCR时,此代码都会在gridview中添加两行。 I have attached the snapshot as well. 我也附上了快照。 Please need kind help. 请需要帮助。 Thanks. 谢谢。
Please use below code. 请使用下面的代码。
Dim nR As Integer =0;
Dim Row As Integer =0;
TxtList.Rows.Add()
Row = TxtList.Rows.Count - 2;
TxtList("stsno", Row ).Value = nR + 1
TxtList("stAcctCode", Row ).Value = txtAccountCode.Text
TxtList("stAcctName", Row ).Value = txtAccountName.Text
TxtList("stBranch", Row ).Value = txtBranchName.Text
TxtList("stDescription", Row ).Value = txtDescription.Text
TxtList("stAmount", Row ).Value = txtAmount.Text
TxtList("stDrCR", Row ).Value = txtDrCr.Text
TxtList.Refresh()
I believe this is the general concept you want. 我相信这是您想要的一般概念。
Private Sub btnAddList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddList.Click
Dim i As Integer
With dgvIssuedBooks
' Write to cell (0,0)
.Rows(i).Cells("CallNumber").Value = txtCallNo2.Text
.Rows(i).Cells("Title").Value = txtTitle2.Text
.Rows(i).Cells("AccessionNumber").Value = txtAccess2.Text
.Rows(i).Cells("Borrower").Value = dgvSearch.Rows(i).Cells("FullName").Value
.Rows(i).Cells("ID").Value = txtShow.Text
End With
txtAccess2.Text = ""
txtCallNo2.Text = ""
txtTitle2.Text = ""
End Sub
Check the spelling all all named objects carefully. 仔细检查所有命名对象的拼写。 Also, just so you know, hitting F11 over and over and over will let you step through the code line by line, so you can see what is actually going on when it runs. 同样,您知道,一遍又一遍地敲击F11,将使您逐行浏览代码,因此您可以看到它运行时的实际情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.