0

如何通过列使用的值的数量(For&Next)对VB.net中的datagridview列标题和列值求和?例子textboxdatagridview

datagridview:之前

          column : ID        address        

                   1         street1 

                   2         street2

                   3         street3

textbox:之后

                  ID = 1 / address = street1 

                  ID = 2 / address = street2 

                  ID = 3 / address = street3 
4

1 回答 1

0

这段代码会将值添加到列表中,您可以从中填充文本框。它假定列的数量未知,并且 dgv 是您的 DataGridView:

    Dim txtBoxList As New List(Of String)
    Dim strLine As String
    For Each dgvRow As DataGridViewRow In dgv.Rows
        For i As Integer = 0 To dgv.Columns.Count - 1
            strLine = strLine & String.Format("{0} = {1}", dgv.Columns(i).HeaderText.ToString, dgvRow.Cells(i).tostring)
            If i < dgv.Columns.Count - 1 Then
                strLine = strLine & " / "
            End If
        Next
        txtBoxList.Add(strLine)
        strLine = String.Empty
    Next
于 2013-02-21T04:50:29.333 回答