Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vb.net中将行添加到datagridview_Vb.net_Data Binding_Datagridview - Fatal编程技术网

在vb.net中将行添加到datagridview

在vb.net中将行添加到datagridview,vb.net,data-binding,datagridview,Vb.net,Data Binding,Datagridview,当我尝试向datagridview添加额外的行时,出现以下错误: 当控件为数据绑定时,无法以编程方式将行添加到DataGridView的Rows集合 如果不进行数据绑定,我会添加如下行: ' Populate the rows. Dim row() As String = {omschrijving, aantalstr, eenheidsprijs, basisbedrag, kortingstr, kortingbedrag, netto, btw, btwbedrag, t

当我尝试向datagridview添加额外的行时,出现以下错误:

当控件为数据绑定时,无法以编程方式将行添加到DataGridView的Rows集合

如果不进行数据绑定,我会添加如下行:

    ' Populate the rows.
    Dim row() As String = {omschrijving, aantalstr, eenheidsprijs, basisbedrag, kortingstr, kortingbedrag, netto, btw, btwbedrag, totaal, productid}

    DataGridView1.Rows.Add(row)

看起来您的网格视图已绑定到数据对象。在这种情况下,您需要将行添加到它绑定到的对象中,就像数据集一样

例如,一个粗略的例子是:

Dim boundSet As New DataSet

Dim newRow As DataRow = boundSet.Tables(0).NewRow
With newRow
    .Item(0) = "omschrijving"
    .Item(1) = "aantalstr"
    ...
End With

boundSet.Tables(0).Rows.Add(newRow)
boundSet.AcceptChanges()

您只需要使用绑定到网格视图的数据集,而不是创建一个新的数据集。

如果数据源是数据绑定的,则应向其添加数据