Search code examples
vb.netdatagrid

Updating to use Option Strict On


I am working on updating a VB.net project to use Option Strict On throughout and seeing this error:

BC32013 Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

However when I try it the code does not work.

Code:

If (dtg_FieldSelector.Rows.Item(m_int_SelectedRow).Cells(0).Value = txt_FieldIndex.Text) Then

Solution

  • you need to stringify the datagrid value as it is Object and Strict on forbids the comparison of two different datatypes

    If (dtg_FieldSelector.Rows.Item(m_int_SelectedRow).Cells(0).Value.ToString() = txt_FieldIndex.Text) Then