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 8342941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:54:42+00:00 2026-06-09T05:54:42+00:00

I have created two comboboxes, one for the min value and one for the

  • 0

I have created two comboboxes, one for the min value and one for the max value. My code should make sure the user doesn’t select a min value greater than the max value, or a max value smaller than the min value using this code.

private void MaxRating_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (MaxRating.SelectedIndex)
            {
                case 0:
                    if (MinRating.SelectedIndex > 0)
                        MinRating.SelectedIndex = 0;
                    break;
                case 1:
                    if (MinRating.SelectedIndex > 1)
                        MinRating.SelectedIndex = 1;
                    break;
                case 2:
                    if (MinRating.SelectedIndex > 2)
                        MinRating.SelectedIndex = 2;
                    break;
                case 3:
                    if (MinRating.SelectedIndex > 3)
                        MinRating.SelectedIndex = 3;
                    break;
                case 4:
                    if (MinRating.SelectedIndex > 4)
                        MinRating.SelectedIndex = 4;
                    break;
            }
        }

However when debugging at the line where it says “if (MinRating.SelectedIndex > 0)” I get “NullReferenceException was unhandled by user code”.

I’m not sure why, I also have a function for MinRating_SelectionChanged, and I don’t seem to be getting anything like that there.

If I remove case:0 from this function, there seems to be no errors. Not from the other function either. I also tried replacing > with == but it just seems to do the same thing.
Any help would be appereciated because I’m just confused.

EDIT: if I just place these two lines

int minrating = MinRating.SelectedIndex;
int maxrating = MaxRating.SelectedIndex;

it gives the error at the second line

  • 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-06-09T05:54:45+00:00Added an answer on June 9, 2026 at 5:54 am

    If carefully analyze, you will see this method may be called even during initialization of the controls, where MaxRating has just been constructed but MinRating is not even constructed. You cannot assume both of them are constructed when this method is called.

    You might check against null for both of them at the beginning of this method as a workaround.

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

Sidebar

Related Questions

Suppose I have two comboboxes. One for the lower-value and one for the upper
I have created two DbContexts, one is for application configuration, the second is for
I have created two folders layout and layout-land with two xml files, one for
I have created two forms in my Windows Application. One Form acts as a
I have created two JavaScript files. One file is "validators.js" and the other is
I have created two viewController classes such that one is superclass of another.i have
How can I add two comboboxes from one store store have type field witch
I have created two forms in the designer, formA and formB, one is a
fI have created two layout files. First one is main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have created two JSP programs as follows. First One: Addmulti.jsp <html> <head><title>Upload Excel

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.