vb.netdatagridviewdbnull

How to set a datagridview row cell to dbnull


I am trying to set a cell to null using code below but after the code runs the cell is not null and actually = ""

isdbnull(cr.Cells(12).Value)

returns

false

using following code

DGV_Fields.DataSource = fieldDT
DGV_Fields.AutoGenerateColumns = True
Dim cr As New DataGridViewRow
fieldDT.Columns.Add("Filter", System.Type.GetType("System.String"))
fieldDT.Columns("Filter").AllowDBNull = True
DGV_Fields.Columns(12).Width = 59
cr = DGV_Fields.SelectedRows.Item(0)
cr.Cells(12).Value = DBNull.Value

Solution

  • changed the last line to

    cr.Cells(12).Value = nothing
    

    now cell is null