• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

How to populate a string based on whether a list box item was selected?

What is wrong with the following if statement to check the value of a ListBox to determine if a choice was made?

$exception      {"Object reference not set to an instance of an object."}

      if (listBox5.ToString().Equals(null))
            {
                branchnum = "";
            }
            else
            {
                branchnum = listBox5.SelectedValue.ToString();
            }
0
zimmer9
Asked:
zimmer9
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try something like:
            if (listBox5.SelectedValue == null)
            {
                branchnum = ""; 
            }
            else
            {
                branchnum = listBox5.SelectedValue.ToString(); 
            }

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now