Hello,
I am having a problem.
I am filling a datagridview straight from an oracle sql query.
The datagridview is filling properly using this code.

Try
            cmd.CommandText = "SELECT *" & _
           "FROM oracle database 

            Dim da As New OracleDataAdapter(cmd)
            Dim DMdt As New DataTable
            da.Fill(DMdt)

            If DMdt.Rows.Count > 0 Then

                Me.DataGridView1.DataSource = DMdt
              'filter the datatable
                da.Dispose()

I then add a column to the datagridview

Dim cbPart As New DataGridViewCheckBoxColumn
                DataGridView1.Columns.Insert(1, cbPart)
                With cbPart
                    .HeaderText = "Part"
                    .Name = "Part"
                    .DisplayIndex = 10
                    .Frozen = False
                End With

The column shows up just fine. However here is when I call a parsing sub to check each box when certain part formats are met. The parsing is working fine in debugging but when a value is true it is throwing an exception.

'do all parsing 
'if conditions are met then
 CType(DataGridView1.DataSource, DataTable).Rows(i).Item("Part") = True
                count = count + 1

The error I am getting is stating that the Part column I am creating does not belong to the table. However it is showing up in the datagridview.
Any help would be appreciated.
Thanks,
Starlight849

Your code would work perfectly if you manually populated the DataGridView.
But because the grid is databound, any changes to the grid layout, ie a new column, will result in an error because that column is not part of the original database table.
The error occurs because the change in the datagrid will trigger an event in the grid to perform a change in the underlying datatable.

Now, if you add a boolean column to the datatable before binding it to the datagrid, then the checkbox column will be shown, and any changes to it will not result in error.

Try
  cmd.CommandText = "SELECT *" & _
  "FROM oracle database 

  Dim da As New OracleDataAdapter(cmd)
  Dim DMdt As New DataTable
  da.Fill(DMdt)

  If DMdt.Rows.Count > 0 Then
    DMDt.Columns.Add(New DataColumn("Part", GetType(Boolean)))

    Me.DataGridView1.DataSource = DMdt
    'filter the datatable
    da.Dispose()

You're amazing! Works perfectly! Thanks so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.