-1

I need your help! I have wrote a function which save the "ID" from a Textfile to a Combobox.

Thats working, now i want to read the "ID" and under the id the values in the textfile when i select the combobox.

Its like

"ID" = L1 220313 100

Values =

  • 1 13
  • 1 25
  • 1 33

So now i want to get the Values which start With 1 in different textboxes, like value 1 13 in textbox1, and so on. But i dont know how to save the startswith in different strings to use them in different ways..

I found this code here in stackoverflow so maybe you know this code

var lines = System.IO.File.ReadAllLines("")
            .Select(l => l.Trim())
            .Where(l => l.StartsWith(l_id // the number));
        comboBox1.Items.Add(String.Join(Environment.NewLine, lines));

this is used to get the ID in the combobox, but i dont know how get the values under the id out of this...

i need something like this

    var sectionName = comboBox1.SelectedItem;
string[] items = 
    File.ReadLines(fileName)                           //read file lazily 
        .SkipWhile(line => line != sectionName)        //search for header
        .Skip(1)                                       //skip header
        .TakeWhile(line => !string.IsNullOrEmpty(line))//take until next header
        .ToArray();    

Source: Read specific line in text file

Thanks in advance!

Community
  • 1
  • 1
Coder64
  • 11
  • 3
  • WinForms, WPF, ASP.NET / ASP.NET MVC.. what are you trying to do? – Arcturus Apr 25 '14 at 07:46
  • What Environment or scope he is in does not matter. this is basic stuff and reecks of a school assignment. Lookup StartsWith. The answer is in your teachers header for the task. You need to loop through the text file. But you need to be alot more specific and show the code you already did. – Christian Apr 25 '14 at 07:50
  • winforms, wait i edit the post and show you my code – Coder64 Apr 25 '14 at 07:56

1 Answers1

1

You can use the SelectedItem property for the combobox. This returns the selected item and then you can get the text from that with the ToString() function. Like this way:

string selected = comboBox1.SelectedItem.ToString();

This way you get the text of the selected item and you can put it in a textbox.

Source:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/b1b5d78e-14c9-4cd2-9f1a-4453edca6c46/combobox-selected-item-text-to-a-string?forum=wpf

markieo
  • 484
  • 3
  • 14
  • i dont want to put the selected item in the textbox, i want to put the lines under the name of the selected item in a textfile in different textboxes, but thank you for your help. – Coder64 Apr 25 '14 at 08:39