473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

hoe to compare a strnig with null value

36
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
Expand|Select|Wrap|Line Numbers
  1. If (ComboBox1.Items.Count = 0) Then
  2.             MessageBox.Show("There are no items in the combobox")
  3.         Else
  4.             Dim str As String
  5.             str = ComboBox1.SelectedItem
  6.            If (str.Equals(Nothing)) Then
  7.                 MessageBox.Show(" No item is selceted", "",    MessageBoxButtons.OK, MessageBoxIcon.Error)
  8.             Else
  9.                 count = count - 1
  10.                 ComboBox1.Items.Remove(str21)
  11.            End If
  12. End If
  13.  
But it gives an error at If(str.Equals(Nothing)) then this line.The error is Object reference is not set to an instance of object.can you help me?
Feb 8 '08 #1
2 1019
debasisdas
8,127 Expert 4TB
Try to use Listindex property.

chek for combo1.Listindex <> -1

to ensure some item is selected.
Feb 8 '08 #2
kunal pawar
297 100+
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.SelectedItem.Text
If str is Nothing Then
MessageBox.Show(" No item is selceted", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
count = count - 1
ComboBox1.Items.Remove(str21)
End If
End If
Feb 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matt | last post by:
I posted this problem before but no reply. Now I repost again. I want to compare the address number in javascript, and the address number is alphanumeric. I have a text box and the user needs to...
5
by: pattanawadee | last post by:
Dear all, I have a problem about compare the 2 variables by use operator 'AND' while one variable is the int constant 0x00000002 and the other one is string '0x202' for the constant...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
17
by: bengamin | last post by:
Hi, I have a C# class and two instance of the class; the class have some property. I want to compare the property value of the two instance How should i do? override == ? use delegate ?
3
by: NathanV | last post by:
I'm trying to compare two byte's. I think I have to use binary operators. How can I tell if two bytes have the same value? Also, I have a function that is returning a byte value. Is there a...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
4
by: Lamis | last post by:
Hi, what is the best way to compare 2 haschtables contatining objects. the objects has 2 property, name & value. I need to print out the differences -- LZ
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.