如何将行中的数据从DataGridView循环到用户窗体

时间:2019-03-10 08:56:09

标签: vb.net

谁能帮助我编辑数据并将其保存回数据库,请在DataGridView中的are复选框中进行检查,以显示需要修改的数据,然后将其转到userform行。行,因为在保存之前需要执行一些计算,到目前为止,循环运行一次并且不会弹出与复选框一样多的表单,而是显示一次并显示1行并停止

Dim i As Integer
Dim list_O_Array As New List(Of Integer)

FrmINI.Show()

For i = FrmINI.DtGrdINI.Rows.Count() - 1 To 0 Step -1
    Dim dlt As Boolean
    dlt = FrmINI.DtGrdINI.Rows(i).Cells(0).Value
    If dlt = True Then
        list_O_Array.Add(i)
    End If
Next

Dim tot As Integer

tot = list_O_Array.Count

For Each k As Integer In list_O_Array
    Dim cnt As Integer

    cnt = 0
    If cnt < tot Then
        frmAddItem.Show()

        frmAddItem.TxtHeading.Text = FrmINI.DtGrdINI.Rows(k).Cells(1).Value
        frmAddItem.TxtPartNumber.Text = FrmINI.DtGrdINI.Rows(k).Cells(2).Value
        frmAddItem.TxtQuantity.Text = FrmINI.DtGrdINI.Rows(k).Cells(4).Value
        frmAddItem.TxtDescription.Text = FrmINI.DtGrdINI.Rows(k).Cells(3).Value
        frmAddItem.TxtUnitCost.Text = FrmINI.DtGrdINI.Rows(k).Cells(5).Value
        frmAddItem.TxtMarginValue.Text = FrmINI.DtGrdINI.Rows(k).Cells(8).Value
    end if
next

1 个答案:

答案 0 :(得分:0)

正如史蒂夫所说,int max_grade = 0;//for storing maximum grade /* Minimum possible value should be initialize here. Best option to write here is: int max_grade = INT_MIN; But to use INT_MIN <limits.h> file must be included. */ int min_grade = 10000000;//for storing maximum grade /* Maximum possible value should be initialize here. Best option to write here is: int min_grade = INT_MAX; But to use INT_MAX <limits.h> file must be included. */ int total_grade = 0;//for counting all the grade for(i = 0; i < count; i++) { if(grade[i] > max_grade){ max_grade = grade[i]; } if(grade[i] < min_grade){ min_grade = grade[i]; } total_grade += grade[i]; } printf("Max grade = %d\n" max_grade); printf("Min grade = %d\n" min_grade); printf("Avg grade = %d\n" total_grade/count); 不会导致frmAddItem.Show()循环停止。它一直运行直到到达最后检查的行。您还可以从For Each表单应显示最后检查的行中的值这一事实中看出。要解决此问题,您必须使用frmAddItem方法(请查看此文档:Form.ShowDialog),并且还必须在设置文本框值后之后放置它,否则将看不到他们。同样在您的代码中,您使用的是ShowDialog()cnt = 0,但是cnt < tot永远不会增量,因此它始终为0。