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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:06:09+00:00 2026-06-11T23:06:09+00:00

I have a loop going through each of my textboxes in Form1 and getting

  • 0

I have a loop going through each of my textboxes in Form1 and getting the tag for them as i will need to compare object IDs. in situations where an object already exist in one of my textboxes, i do not want to allow the user to add this object again, but if this object does not exist in any of the textboxes, only then can the user add this item.

I have tried it with this loop below but it doesnt seem to work as it keeps telling me “Object reference not set to an instance of an object.” on this line if (resval.types.xan_ID == tbItems.types.xan_ID)
after i get the message box which i want, how can I change this code to achieve this goal.

                        // Get the name which will be passed into the textbox
                        var resval = form2result.getValue();

                        //go through each of my textbox
                        foreach (TextBox tb in TextBoxList)
                        {
                            var tbItems = (ReportItems)tb.Tag;
                            if (tb.Text != "")
                            {
                                //if the item returned is the same as an item in the textbox
                                if (resval.types.xan_ID == tbItems.types.xan_ID)
                                {
                                    // display this message and break out of the loop
                                    MessageBox.Show("You have previously selected this report, please chose another");
                                    break;
                                }
                                    // otherwise add the item into the textbox.
                                else
                                {
                                    // otherwise add name to the textbox
                                    _dict[sender].Text = resval.ToString();
                                }
                            }   
                        }

ReportItems

public class ReportItems
{
    public DataSet1.xspGetAnalysisTypesRow types { get; set; }

    //Analysis types or Reports
    public ReportItems(DataSet1.xspGetAnalysisTypesRow analysisTypes)
    {
        types = analysisTypes;
    }

    //Return the name of this type. 
    public override string ToString()
    {
        return this.types.xan_Name;
    }
}

getValueFunction (This is in a different form)

    public ReportItems getValue()
    {
        ReportItems selection = (ReportItems)reportListBx.SelectedItem;

        // if user has selected a value             
            return selection;           
    }
  • 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-11T23:06:10+00:00Added an answer on June 11, 2026 at 11:06 pm

    I’m not sure what the link is between _dict[sender] and TextBoxList but you haven’t set the Tag as the same point as setting the text. Assuming these are referring to the same object this will cause an error the next time you use this method as you’ll have a text box with no tag.

                        // Get the name which will be passed into the textbox
                        var resval = form2result.getValue();
                        // The user didn't select anything somehow.
                        if (resval == null)
                        {
                          MessageBox.Show("Nothing Selected"); 
                          return;
                        }
                        // resval hasn't been setup correctly.
                        if (resval.types == null)
                        {
                          MessageBox.Show("Internal Error"); 
                          return;
                        }
                        Boolean alreadyExists = false;
                        //go through each of my textbox
                        foreach (TextBox tb in TextBoxList)
                        {
                            var tbItems = (ReportItems)tb.Tag;
                            //The Textbox must contain text and tbItems must not be null
                            if (tb.Text != "" && tbItems != null)
                            {
                                //The tag has been set, but somehow the types are null?
                                if (tbItems.types == null)
                                {
                                    MessageBox.Show("Internal Error");    
                                break;
                                }
                                //if the item returned is the same as an item in the textbox
                                if (resval.types.xan_ID == tbItems.types.xan_ID)
                                {
                                    alreadyExists = true;
                                    // display this message and break out of the loop
                                    MessageBox.Show("You have previously selected this report, please chose another");
                                    break;
                                }
                                    // otherwise add the item into the textbox.
                            }   
                        }
                        if (!alreadyExists)
                        {
                            // otherwise add name to the textbox
                            _dict[sender].Text = resval.ToString();
                            //set the tag? 
                            _dict[sender].Tag = tbItems;
                        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a foreach loop in jQuery going through each 'div.panel', I need to
I have a loop thats going through all div's in a table cel with
I'm getting a JSON response from the server and i have to loop through
I have this VBA below that is designed to loop through each WS and
Hello I have a loop that will need to count the number of occurrences
I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
I have a loop that enters each non-empty text field into a database: foreach
I have a loop $(.box).find('.video, .print, .web').closest('.box').each(function (index) { $(this).delay(100 * index).fadeIn(300); }); This
What I'm trying to do involves going through a series of checkboxes. For each
I need to generate several reports, and many of them will simply be a

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.