Click here to Skip to main content
15,910,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what code can I use to display two array elements(double datatypes) in a textbox or richtextbox so that the two arrays can be in form of table. That is
Array1 Array2
0.89 0.21
2.50 3.08.
And so on until the last array element.
Posted
Comments
Matt T Heffron 15-May-15 19:27pm    
If you use a TextBox or RichTextBox there's no straightforward way to enforce keeping the data as a two column table of numbers.
Since you said TextBox or RichTextBox, I take it you intend to allow them to be edited.
A table of TextBox or RichTextBox, one for each value, is probably what you want.

Hi,

You can achieve what you want by creating a string and appending the values from each array by looping through each element of the array. Here is the code:

C#
double[] array1 = new[] {1.1, 2.2, 3.3};
            double[] array2 = new[] { 4.4, 5.5, 6.7 };
            StringBuilder textBuilder = new StringBuilder();
            int arrayLength = array1.Length;
            for (int loop = 0; loop < arrayLength; loop++)
            {
                textBuilder.Append(array1[loop] + " " + array2[loop] + "\n");
            }
            richTextBox1.Text = textBuilder.ToString();


Note: For this to work without exception both the arrays should be of same length.
 
Share this answer
 
Listen to a good advice: don't do it. One of the best options would be DataGridView:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900