Calum Harris
Calum Harris

Reputation: 73

Multiline Textbox Columns C#

So as apart of my course work I have to output the totals sales of 5 books by their author. Here is an example as to how it should look: Example

My question is how can I achieve an output in the text box where the Author names are in a fixed position like above. I would suspect you could do this with columns but I'm still learning and yet to have any experience with them. After this I need to sort the lists based on price relative to the authors. Currently I just have a simple output that pushes out the numbers from an array storing the total sales:

private void uiAuthorChartButton_Click(object sender, EventArgs e)
    {
        UpdateAuthorSales();

        uiAuthorChartTextBox.Clear();

        for (int outputAuthorChart = 0; outputAuthorChart <= salesByAuthor.Length - 1; outputAuthorChart++)
        uiAuthorChartTextBox.AppendText("£" + salesByAuthor[outputAuthorChart].ToString() + "\r\n");
    }

Upvotes: 2

Views: 1081

Answers (2)

Mayura Vivekananda
Mayura Vivekananda

Reputation: 674

Consider PadRight.

Allows you to pad out a string with spaces. If you do a bit of maths with the size of string required, and the length of the string you have, you should be able to calculate the number of spaces needed.

I will leave you to implement it, because the best way to learn is by doing.

Upvotes: 0

Jerry
Jerry

Reputation: 4408

You can use one or more tab characters \t before the author name in the string

Upvotes: 1

Related Questions