TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SUNIL GUTTA
NA
1k
394k
unable to handle null values in ComboBox ?
Feb 21 2013 3:51 AM
Hie friends
Well i used a button and combo box . when i click on button it should display what ever i selected in combo box :) when i select something in comboBox its working fine but when i un-intentionally click on button without selecting anything in comboBox ITS THROWING me Null Reference Exception :(
How to handle this ? Is there any other way except exceptional handling ?
My Code :
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedItem.ToString());
}
(OR)
private void button1_Click(object sender, EventArgs e)
{
foreach(object obj in ComboBox1.SelectedItem.ToString())
MessageBox.Show(obj.ToString());
}
Foreach also failed to handle null but its not used here in this context :D
Thank you in advance
Reply
Answers (
3
)
How to bulk upload images to SQL Server using windows forms
C# window form application; send txt sms to cell phone