Sure, here's the repro code. Also as I noted previously this did not throw
an error in 1.1.
I am including the form code and the designer code below. Click Setup, then
click Error, and the error will appear.
I currently have two workarounds: a) set the dataview's datasource to
nothing, add the column, then set it back to datatable b) take out
beginloaddata and endloaddata.
-B
-------------------- BEGIN FORM CODE ------------------------
Imports System.Data
Public Class Form1
Private Sub cmdSetup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSetup.Click
Dim table As DataTable = New DataTable("Flowchart")
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn
myDataColumn.DataType = GetType(System.String)
myDataColumn.ColumnName = "Flowchart"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Flowchart"
myDataColumn.Unique = False
table.Columns.Add(myDataColumn)
' Hidden column for object type
myDataColumn = New DataColumn
myDataColumn.DataType = GetType(System.Double)
myDataColumn.ColumnName = "ObjectType"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "ObjectType"
myDataColumn.Unique = False
table.Columns.Add(myDataColumn)
' hidden column for sort string
myDataColumn = New DataColumn
myDataColumn.DataType = GetType(System.String)
myDataColumn.ColumnName = "Sort"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "Sort"
myDataColumn.Unique = False
table.Columns.Add(myDataColumn)
Dim dataview As New DataView(table)
dataview.Sort = "ObjectType, Sort"
grdFlowChartOrig.DataSource = dataview
AddFlowChartRow(2, "A")
AddFlowChartRow(3, "B")
AddFlowChartRow(1, "C")
AddFlowChartRow(4, "D")
AddFlowChartColumn(table)
AddFlowChartColumn(table)
AddFlowChartColumn(table)
AddFlowChartRow(2, "A")
AddFlowChartRow(3, "B")
AddFlowChartRow(1, "C")
AddFlowChartRow(4, "D")
grdFlowChartOrig.Refresh()
End Sub
Private Sub cmdError_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdError.Click
Dim objTable As DataTable = DirectCast(grdFlowChartOrig.DataSource,
DataView).Table
Dim objView As DataView = DirectCast(grdFlowChartOrig.DataSource,
DataView)
objTable.Rows.Clear()
objTable.BeginLoadData()
While objTable.Columns.Count > 3
objTable.Columns.RemoveAt(objTable.Columns.Count - 1)
End While
AddFlowChartRow(3, "E")
AddFlowChartRow(1, "E")
AddFlowChartRow(2, "E")
AddFlowChartColumn(objTable)
objTable.EndLoadData()
objTable.AcceptChanges()
End Sub
Public Sub AddFlowChartRow(ByVal nObjectType As Double, Optional ByVal
strSort As String = "")
Static i As Integer = 0
Dim objTable As DataTable = DirectCast(grdFlowChartOrig.DataSource,
DataView).Table
Dim objRow As DataRow = objTable.NewRow()
objRow(0) = "row" & CStr(i)
objRow(1) = nObjectType
objRow(2) = strSort
objTable.Rows.Add(objRow)
i = i + 1
End Sub
Public Sub AddFlowChartColumn(ByVal objTable As DataTable)
Static i As Integer = 0
Dim myDataColumn As New DataColumn
myDataColumn.DataType = GetType(System.String)
myDataColumn.ColumnName = "new column" & CStr(i)
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "new column" & CStr(i)
myDataColumn.Unique = False
objTable.Columns.Add(myDataColumn) ' ERROR THROWN HERE
i = i + 1
End Sub
End Class
-------------------- END FORM CODE ---------------------------
-------------------- BEGIN DESIGNER CODE --------------------
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.grdFlowChartOrig = New System.Windows.Forms.DataGridView
Me.cmdSetup = New System.Windows.Forms.Button
Me.cmdError = New System.Windows.Forms.Button
CType(Me.grdFlowChartOrig,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'grdFlowChartOrig
'
Me.grdFlowChartOrig.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.grdFlowChartOrig.Location = New System.Drawing.Point(12, 35)
Me.grdFlowChartOrig.Name = "grdFlowChartOrig"
Me.grdFlowChartOrig.Size = New System.Drawing.Size(423, 169)
Me.grdFlowChartOrig.TabIndex = 0
'
'cmdSetup
'
Me.cmdSetup.Location = New System.Drawing.Point(454, 49)
Me.cmdSetup.Name = "cmdSetup"
Me.cmdSetup.Size = New System.Drawing.Size(100, 58)
Me.cmdSetup.TabIndex = 1
Me.cmdSetup.Text = "Setup"
Me.cmdSetup.UseVisualStyleBackColor = True
'
'cmdError
'
Me.cmdError.Location = New System.Drawing.Point(457, 129)
Me.cmdError.Name = "cmdError"
Me.cmdError.Size = New System.Drawing.Size(97, 58)
Me.cmdError.TabIndex = 2
Me.cmdError.Text = "Trigger Error"
Me.cmdError.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(580, 253)
Me.Controls.Add(Me.cmdError)
Me.Controls.Add(Me.cmdSetup)
Me.Controls.Add(Me.grdFlowChartOrig)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.grdFlowChartOrig,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Friend WithEvents grdFlowChartOrig As System.Windows.Forms.DataGridView
Friend WithEvents cmdSetup As System.Windows.Forms.Button
Friend WithEvents cmdError As System.Windows.Forms.Button
End Class
------------------------- END DESIGNER CODE ---------------------------------