473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Txt File Problem C#

been working on this all day and cant figure out a solution

for (int i = 0; i < NumberOfLines; i++)
{
ID[i] = tr.ReadLine();
lines = ID[i].Split(new Char[] { ' ' });
comboBox1.Items.Add(lines[0]);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = lines[1];
}

ok problem is lines[1] only reads the end of the array and i allways get the last result no matter what i do to try to change it, but lines[0] works fine??? how can i get the textbox to only show the right thing based on what lines[0] is.
example lines[0] = 1
how can i get lines[1] to display the first line.
lines[0] = 2
how can i get lines[1] to display the 2nd line and so forth.
Aug 22 '08 #1
12 1408
or at least tell me how i can do this

string[,] threebythree = new string[Int16.Parse(ID[i]), Int16.Parse(lines[i])];
because even with the conversions i get
ERROR: Input string was not in a correct format.
Aug 22 '08 #2
tlhintoq
3,525 Expert 2GB
Not exactly sure what the goal here is... But looks like if you pick the second item from a list box (iteration 1 since it is zero indexed) that you want the second line of your file to appear in a text box. Fourth item selected in the listbox = fourth item in the text box. Is that the goal?

Both are zero-indexed. So take the .SelectedIndex value from the listbox and use that as the line number index to show in the text box.

If I have mis-understood your goal and lead you astray, my deepest apologies.
Aug 22 '08 #3
sry i said it in a confusing way.

The text file has this in it:
0 string1 5
1 string2 10
2 string3 15

lines[0] is 0, 1, 2
lines[1] is string1, string2, string3
lines[2] is 5, 10, 15

ID[0] is 0 string1 5
ID[1] is 1 string2 10
ID[2} is 2 string3 15

when i try to write lines[1] to textbox1.text im getting string3 only.
i dont know the code to make it string1 first then string2, then string3.
so its reading the last array first.
i would like to make it possible to just have an array like (ID[i], lines[i]) thats what i tried doing in the reply but of course that doesnt work.
Aug 22 '08 #4
i know how to write it to a text file and it works 100%

for (int i = 0; i < NumberOfLines; i++)
{
ID[i] = tr.ReadLine();
lines = ID[i].Split(new Char[] { ' ' });
comboBox1.Items.Add(lines[0]);
PrintValues(lines[1]);
}

private void PrintValues(IEnumerable myList)
{
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while (myEnumerator.MoveNext())
tw.Write("{0}", myEnumerator.Current);
tw.WriteLine();
}

each time i select a new ID it writes to the file with the correct lines[1] i want to do the same thing but have it just write into the textbox not a file...
Aug 22 '08 #5
r035198x
13,262 8TB
Well then just set it as the textbox's Text property.
Aug 22 '08 #6
i've allready tried that it doesnt work correctly....thats the whole reason i made this post, if i try lines[1] in the textbox i get the last array only aka string3.
Aug 22 '08 #7
r035198x
13,262 8TB
i've allready tried that it doesnt work correctly....thats the whole reason i made this post, if i try lines[1] in the textbox i get the last array only aka string3.
That's because you are adding the values in a loop and at each run the previous value gets overwritten. So at the end you have only the last value set. Use a StringBuilder and append the text to a StringBuilder in the loop. You then set the value of the textbox after the loop using the string stored in the StringBuilder.
Aug 22 '08 #8
ok then thats what i havnt learned how to do before how do you make a stringbuilder.
Aug 22 '08 #9
r035198x
13,262 8TB
ok then thats what i havnt learned how to do before how do you make a stringbuilder.
Se this article
Aug 22 '08 #10
according to that a string builder can do the same thing but theres a difference in speed, i tried that and it does show all the strings together now string1string2string3 in the textbox but now i've gotta split that up...

i figured out a way to do it without the string builder though thx for your help the last post did make me realize what i did wrong.
Aug 22 '08 #11
r035198x
13,262 8TB
according to that a string builder can do the same thing but theres a difference in speed, i tried that and it does show all the strings together now string1string2string3 in the textbox but now i've gotta split that up...

i figured out a way to do it without the string builder though thx for your help the last post did make me realize what i did wrong.
Glad you got it.
Aug 22 '08 #12
Plater
7,872 Expert 4TB
You could have just been saying your loop:
mytextbox.Append(lines[1]+"\r\n");
Aug 22 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.