Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6938947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:33:24+00:00 2026-05-27T12:33:24+00:00

The application runs fine – But if the user selects NOTHING from the listboxes

  • 0

The application runs fine – But if the user selects NOTHING from the listboxes and instead just hits the ‘Do We Match’ button – that crashes the program. I need it to throw up an error requesting that they click a starsign in each list (official error is ‘Null Reference Exception is unhandled).

Code for that part so far:

// Method for starsign combinations
public void Combinations()
{
    ListBoxItem lbi = (ListBoxItem)yourListBox.SelectedItem;
    string yourListBoxValue = (string)lbi.Content;

    ListBoxItem lbi2 = (ListBoxItem)partnerListBox.SelectedItem;
    string partnerListBoxValue = (string)lbi2.Content;

    string listBoxValuesCombined = yourListBoxValue + partnerListBoxValue;

    if ((listBoxValuesCombined == "Aries" + "Aries") || (listBoxValuesCombined == "Aries" + "Aries"))
        resultTextBlock.Text = "On Fire - this is a hot combination!";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:33:25+00:00Added an answer on May 27, 2026 at 12:33 pm

    Check the SelectedItem properties of your ListBoxes before you access the Content property of each ListBoxItem. Since you want both ListBoxes to have a value before you continue, put this check for null at the top of your Combinations method:

    public void Combinations()
    {
      if (yourListBox.SelectedItem == null || partnerListBox.SelectedItem == null)
      {
        resultTextBlock.Text = "Please select a sign for yourself and your partner.";
        return;
      }
    

    If there is no value selected in the ListBox, then the SelectedItem property will be null. So, when you get the ListBoxItem above:

    ListBoxItem lbi = (ListBoxItem)yourListBox.SelectedItem;
    

    lbi ends up with the value null. The NullReferenceException is thrown when you then try to get lbi.Content. Since lbi is null, it doesn’t have an object to get the Content property from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that runs fine under IIS5 or IIS6. I just
I have a .net 3.5 WinForms application that runs fine on my machine, but
I have application built on asp.net MVC3. Application runs fine but I see one
My rails application runs fine on my local testing server, but when I deploy
My Application runs fine in iPad simulator, but when i try to install it
I have a server application which runs fine in most of the cases but
I have a ASP.NET MVC application using NHibernate and the application runs fine when
I have an application that runs fine when executed off the server. When clients
I have a WPF application that runs fine under XP as an administrator. When
I have an .Net MVC application which runs fine if I use the build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.