【问题标题】:Error on Row add in UltraGrid InfragisticsUltraGrid Infragistics 中的行添加错误
【发布时间】:2017-02-10 10:29:13
【问题描述】:

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

上下文不足,无法添加新行。在这个带中的一行或 父带必须处于活动状态才能提供足够的上下文。

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

任何帮助将不胜感激。

【问题讨论】:

  • 调用 AddNew 时网格是否为空(或未设置 DataSource)?
  • 是的,它是空的,没有数据源。
  • 如果网格不知道要显示哪些列,你认为它如何能够创建一行?
  • 那我该怎么办?
  • 我只在代码中定义了列。

标签: vb.net infragistics ultrawingrid


【解决方案1】:

为了在运行时添加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 设计器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多