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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:37:37+00:00 2026-05-16T14:37:37+00:00

I use the same code to fill a control in my WinForms over and

  • 0

I use the same code to fill a control in my WinForms over and over again, so I figured: Hey, you should make it a method instead of copy-pasting it!

So, I created this in my Main class

Main

internal static void FillWithStuff(RichTextBox box)
{
 Data data = GetSomeData("doesn't matter");
 foreach (Row row in data)
 {
  box.Text += row.ToString() + "\r\n";
 }
}

WinForm

internal RichTextBox textBox = new RichTextBox();
// Some code
Main.FillWithStuff(textBox);

So, the method executes without exceptions or warnings, but the data is not filled in the box. I checked if the data was loaded and it is, so the problem has to be somewhere else.

How should I implement this correctly?

  • 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-16T14:37:38+00:00Added an answer on May 16, 2026 at 2:37 pm
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private List<string> GetStuff()
            {
                List<string> stuff = new List<string>();
    
                stuff.Add("foo");
                stuff.Add("bar");
                stuff.Add("baz");
    
                return stuff;
            }
    
            private void FillWithStuff(TextBoxBase textBox)
            {
                List<string> stuff = GetStuff();
    
                foreach (string s in stuff)
                {
                    textBox.Text += s + "\r\n";
                }
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                FillWithStuff(richTextBox1);
            }
        }
    }
    

    That works as you would expect. Comparing it with what you have makes me think you have a problem somewhere else. Are you sure row.ToString() is returning a non-empty string?

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

Sidebar

Related Questions

I would like to use the same code for copying files to an FTP
I use this code to update data in database table. Can reuse same code
I have Java code and TeX documents in the same project. I use TeXlipse
I'm writing code in which I use MATLAB's fill command to plot 2D shapes.
I am trying to use same validation function for all my controls. But I
Previously, I have an app that uses core data. I use same store url
Can the application use set same char in the XON and XOFF? If yes,
I want to use the same ant script to do a build in either
I want to use the same style in many listviews. And in my style
how can I use the same UI template (*.ui.xml file) with multiple Java objects

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.