在vb.net中将行添加到datagridview
当我尝试向datagridview添加额外的行时,出现以下错误: 当控件为数据绑定时,无法以编程方式将行添加到DataGridView的Rows集合 如果不进行数据绑定,我会添加如下行:在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
' 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()
您只需要使用绑定到网格视图的数据集,而不是创建一个新的数据集。如果数据源是数据绑定的,则应向其添加数据