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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:12:01+00:00 2026-05-23T02:12:01+00:00

I am trying to read value from a listbox item that is on another

  • 0

I am trying to read value from a listbox item that is on another thread.

I tried to make a new method to run the invoke command, I can manage to send a command to the listbox like add via the invoke method but i cant seem to get a response, i cant seem to get the value of the item, i have tried a few ways, once i change it from a void to a string things start to get hairy…

  thread t1 = new thread(thethread)
    t1.start()

    public void thethread()
    {
    string text = readListBoxSelected(listBox1) + " lala" ;
    }



    public static string readListBoxSelected(ListBox listbox)
    {
        if (listbox.InvokeRequired)
        {
            return (string)listbox.Invoke(
              new Func<String>(() => readListBoxSelected(listbox))
            );
        }
        else
        {

            string varText = listbox.SelectedValue.ToString();
            return varText;
        }
        }

Above is a example of what i am trying to do.

Here is the error:

System.NullReferenceException was
unhandled by user code
Message=Object reference not set to an
instance of an object.
Source=** StackTrace:
at **.Form1.readListBoxSelected(ListBox listbox) in e:\documents and
settings\scott\my documents\visual
studio
2010\Projects*****\Form1.cs:line
133
at
***.Form1.<>c_DisplayClass5.b_3()
in e:\documents and settings\scott\my
documents\visual studio
2010\Projects******\Form1.cs:line
127 InnerException:

I imagine what is wrong is exactly what it says “Object reference not set to an instance of an object”……. All my variables seem to be declared as fair as i am aware, how can i correct this??

I get the feeling i am going about the entire thing wrongly…. 0_o
Thanks in Advance,
Scott

  • 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-23T02:12:01+00:00Added an answer on May 23, 2026 at 2:12 am

    Try This

    public static string readListBoxSelected(ListBox listbox)
        {
            if (listbox.InvokeRequired)
            {
                return (string)listbox.Invoke(
                  new Func<String>(() => readListBoxSelected(listbox))
                );
            }
            else
            {
    if(istbox.SelectedValue != null)
    
                return  listbox.SelectedValue.ToString();
    else
    return String.Empty
            }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a value from a file and use it in a
I am trying to read the value of my slider from a DIV element's
I trying to read a value from an ArrayCollection, I use getItemAt and get
iam confused. Iam trying to read an Value from an oracle table, format: timestamp(6).
I am trying to get my program to read a value from a particular
I'm trying to read the value of a C# property from my code behind
I'm trying to read a character represented by the hex value 0x80 from a
I'm trying to remove some objects from a ListBox that I have created, and
I am trying to read in a hex value from a text box and
I am trying to read a value from the Local security policies using C#.

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.