hoe to compare a strnig with null value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sdanda
    New Member
    • Oct 2007
    • 36

    hoe to compare a strnig with null value

    Hai,
    i am working on windows applications. In my applicaion One combobox, one button(neamed as delete) is there.
    I would like to delete the selected combobox item .So I wrote code to delete a selected item under delete button click. In this i want to check if the combobox selected item is null, after clicking on the button delete it displays some error message like, "There is no item to delete. You selected nothing."

    i wrote this code
    [code=vbnet]
    If (ComboBox1.Item s.Count = 0) Then
    MessageBox.Show ("There are no items in the combobox")
    Else
    Dim str As String
    str = ComboBox1.Selec tedItem
    If (str.Equals(Not hing)) Then
    MessageBox.Show (" No item is selceted", "", MessageBoxButto ns.OK, MessageBoxIcon. Error)
    Else
    count = count - 1
    ComboBox1.Items .Remove(str21)
    End If
    End If
    [/code]
    But it gives an error at If(str.Equals(N othing)) then this line.The error is Object reference is not set to an instance of object.can you help me?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Try to use Listindex property.

    chek for combo1.Listinde x <> -1

    to ensure some item is selected.

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      try this one

      If ComboBox1.Items .Count <= 0 Then
      MessageBox.Show ("There are no items in the combobox")
      Else
      Dim str As String
      str = ComboBox1.Selec tedItem.Text
      If str is Nothing Then
      MessageBox.Show (" No item is selceted", "", MessageBoxButto ns.OK, MessageBoxIcon. Error)
      Else
      count = count - 1
      ComboBox1.Items .Remove(str21)
      End If
      End If

      Comment

      Working...