Search code examples
vb.netform-load

VB.NET :Error on combobox's SelectedValueChanged event on form's load


I've a function fill_cboarea(to fill a combobox called cboarea).This function will call on Form_load.While reaching this fill_cboarea func debugger goes to cboarea_SelectedValueChanged because i have written some piece of code in it.Below given is the error.

Operator '<>' is not defined for type 'DataRowView' and type 'Integer


Solution

  • you need a checking in cboarea_SelectedValueChanged
    i.e

    Private Sub cboarea_SelectedValueChanged(ByVal sender As Object, ByVal e As 
                                 System.EventArgs) Handles cboarea.SelectedValueChanged
    
        Dim item As DataRowView = TryCast(Me.cboarea.SelectedItem, DataRowView)    
        If item.IsEdit = False Then'check whether the cboarea is in edit mode (on load)
           'here your some piece of code
        End If
    End Sub