UltraGrid Infragistics中的行添加错误

时间:2017-02-10 10:29:14

标签: vb.net infragistics ultragrid

尝试在UltraGrid中添加行时出现此错误

  

没有足够的上下文来添加新行。在这个乐队中的一行或者   父乐队必须积极提供足够的背景。

使用以下代码行添加新行。但是给出错误。 myGrid.DisplayLayout.Bands(0).AddNew()

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

为了在运行时添加UltraGrid行,UltraGrid的数据源属性必须不同于null。这样,UltraGrid熟悉数据源上下文,并根据已提供的数据模式添加新行。否则UltraGrid不知道新行应该是什么样子。有关更多信息,请参阅以下文档页面 - Add Rows to WinGrid Programmatically

Private Sub Form1_Load(sender As Object, e As EventArgs)
    ' Create a table that will contain three columns
    Dim table As New DataTable("Table")

    ' Create three columns that will hold sample data
    Dim column1 As New DataColumn("Column 1", GetType(String))
    Dim column2 As New DataColumn("Column 2", GetType(Integer))
    Dim column3 As New DataColumn("Column 3", GetType(System.Drawing.Color))

    ' Add the three columns to the table.
    table.Columns.AddRange(New DataColumn() {column1, column2, column3})

    ' Assign grid's data soure to the newly created table
    Me.ultraGrid1.DataSource = table
End Sub

Private Sub ultraButton1_Click(sender As Object, e As EventArgs)
    ' Now this line of code works! 
    Me.ultraGrid1.DisplayLayout.Bands(0).AddNew()
End Sub

或者,如果您想在设计时定义数据模式,可以使用UltraDataSource组件和UltraGrid设计器。

enter image description here

相关问题