I have a procedure that looks like this
Public Shared Sub FillMultiColumn(ByVal srcDataGridView As DataGridView, ByVal strColumnWidths As String, _
ByVal intColumnNumber As Integer, ByVal strCommand As String, ByVal columnName As String, _
ByVal strDisplayMember As String, ByVal strValueMember As String, _
Optional ByVal srcCommandType As CommandType = CommandType.Text)
clsConnections.SetSQL()
Try
Dim myCmd As SqlCommand = New SqlCommand(strCommand, clsConnections.connSQL)
myCmd.CommandType = srcCommandType
Dim da As SqlDataAdapter = New SqlDataAdapter(myCmd)
Dim ds As New DataSet
da.Fill(ds, "temp")
Dim dt As DataTable = ds.Tables("temp")
Dim position = srcDataGridView.Columns(columnName).Index
Dim newColumn As New DataGridViewMultiColumnComboColumnDemo.DataGridViewMultiColumnComboColumn
newColumn.AutoSizeMode = srcDataGridView.Columns(columnName).AutoSizeMode
newColumn.HeaderText = srcDataGridView.Columns(columnName).HeaderText
newColumn.Width = srcDataGridView.Columns(columnName).Width
newColumn.Name = columnName
newColumn.CellTemplate = New DataGridViewMultiColumnComboColumnDemo.DataGridViewMultiColumnComboCell
newColumn.DataSource = dt
newColumn.DisplayMember = strDisplayMember
newColumn.ValueMember = strValueMember
If srcDataGridView.ColumnCount > 0 Then
srcDataGridView.Columns.Remove(columnName)
End If
''' ----> the suspicious part
srcDataGridView.Columns.Insert(position, newColumn)
''' ----> end of the suspicious part
newColumn = Nothing
ds.Dispose()
myCmd.Dispose()
myCmd.Dispose()
Catch ex As Exception
MsgBox("Error : FillMultiColumn in clsProcedures." & vbCrLf & ex.Message, MsgBoxStyle.Exclamation, "Error")
Finally
clsConnections.connSQL.Close()
clsConnections.connSQL.Dispose()
End Try
End Sub
Let's just say, one of the forms called this procedure and when that form closes, it will have "ArgumentOutOfRangeException" exception. But if i remove the suspicious part, it won't give any error...
Please i need your help, thank you...
Additional question, when the
DataGridView.AllowUserToAddRows is changed, does the datagridview pass something to the column that tells the column that the
DataGridView.AllowUserToAddRows is false or true?