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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:51:20+00:00 2026-05-26T03:51:20+00:00

I have listbox of strings. When I select one of this strings, I split

  • 0

I have listbox of strings. When I select one of this strings, I split it.

I want to send to the textboxes the split values of this string. How do I send the values to the textboxes?

I have this C# code:

private void button8_Click(object sender, EventArgs e)
{
    string Code;
    string Name;
    string PName;
    string Cost;
    string Num;
    string Level;

    using (var streamReader = new StreamReader(filePath, Encoding.Default))
    {
        if (!streamReader.EndOfStream)
        {
            Items.Add(streamReader.ReadLine());//list Items
        }
    }

    string z = listBox1.SelectedItem.ToString();

    string[] words = x.Split(',');
    foreach (string word in words)
    {
       if (words.Length == 6)
       {
            Code = words[0];
            Name = words[1];
            PName = words[2];
            Cost = words[3];
            Num = words[4];
            Level = words[5];
        }                
    }

    textBox1.Text = Code;       //This does not send anything to the textbox
    textBox2.Text = Name;
    textBox3.Text = PName;
    textBox4.Text = Cost;
    textBox5.Text = Num;
    textBox6.Text = Level;

    using (var streamWriter = new StreamWriter(
           filePath, false, Encoding.Default))
    {
        foreach (string op in Items)
        {
            streamWriter.WriteLine(op);
        }
    }
}

The C# code that does textBox1.Text = Code; does not send any text to the textbox, how do I assign a string to a textbox?

  • 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-26T03:51:20+00:00Added an answer on May 26, 2026 at 3:51 am

    Your Code variable is still null when you are assigning it to the TextBox.

    Change it to:

    string Code = string.Empty;
    // etc.
    

    Based on your sample code though, you shouldn’t need any of those string variables or your ForEach. Just assign it straight to your TextBoxes.

    textBox1.Text = words[0];
    textBox2.Text = words[1];
    textBox3.Text = words[2];
    textBox4.Text = words[3];
    textBox5.Text = words[4];
    textBox6.Text = words[5];
    

    And try giving your controls names, too. textBox4 doesn’t tell you it has anything to do with cost.

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

Sidebar

Related Questions

I have a string 'item3' and a listbox with 'item1,item2,item3,item4', how do I select
I have a webpart and I want to select mulitple items in a listbox,pretty
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a ListBox which displays items of variable height. I want to show
I have a ListBox to which I bound a sorted list of strings. I
I have list box control where I am binding the values to the listbox
Suppose you have a fixed list of values (strings): None, Skype, ICQ, GoogleTalk, MSN
I have a listbox bound to a view model observable collection: This works fine,
I have this method Verify_X which is called during databind for a listbox selected
I have this ListBox which is bound to an ObservableCollection. Each object in the

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.