Re: help - populating a combox box from a text file and updating a listbox automatically



Ok,

The item in the ComboBox have some text that should be displayed in the TextBox. This text is taken from another file and can be shared among several items in the ComboBox.

How to find the text in the 'text'-file depends on how it is formatted. You could compare with combobox, value, using a similar method of ReadAllLines and search with String.BeginsWith("AAAA"), or do a string[] items = String.Split(';') and compare the comboBox value with items[0].. If the text is limited, you could also put it in the same file as the ComboBox values and store the text along with the display value. You can create a separate class for this

public class ComboBoxItem
{
private string display = "";
private string value = "";

public string Display
{
get{ return display; }
}

public string Value
{
get{ return value; }
}

public ComboBoxItem(string display, string value)
{
this.display = display;
this.value = value;
}
}

The ComboBox should then be filled like this


foreach(string s in lines)
{
string text = ...
string[] items = s.Split(';');
comboBox1.Items.Add(new ComboBoxItem(items[0], text));

if(items.Length > 1)
for(int i = 1; i < items.Length; i++)
comboBox.Items.Add(new ComboBoxItem(" " + items[i], text));
}


It will be easier to come up with code ideas if you have a clearer idea of what you are trying to achieve.



On Tue, 07 Nov 2006 12:57:54 +0100, CCLeasing <gary@xxxxxxxxxxxxxxx> wrote:


I have no edit facilty please find repost with corrected example

Thankyou very much that's exactly what i wanted.

Now i just need to get part two the updating of the textbox working.

Can you give me an example of some code that would find the line that
starts with the value of the combo box, and then store the text of that
line that occurs after a semicolon to a string, and set this string as
the value of the textbox control.

e.g.


combo box value: AAAA

on update check the text file textbox.txt for a line begininning with
AAAA e.g.

CCCC; some other text
AAAA ; "sometext for the text box here"
BBBB ; some other text

and then set the textbox controls text equal to "sometext for the text
box here" because that is the text that is after the semicolon on the
AAAA line.

Thankyou




--
Happy Coding!
Morten Wennevik [C# MVP]
.



Relevant Pages

  • Re: Displaying results in GUI
    ... 'String', 'your new text')} would result in displaying the new text ... {If the tag property for your textbox is: ... >> GUI is run. ... > I'm able to display the numerical result with out converting it to ...
    (comp.soft-sys.matlab)
  • Re: Combobox display und value member
    ... Die Werte für Display und Valuemember sind Eigenschaftsnamen, welche jedes Object in der DataSource-Auflistung anbieten muss. ... Dadurch dass deine eingefügten Werte strings sind, kann deine Data oder Value Eigenschaft nur eine Property des String datentyps sein. ... Deine ComboBox weiss nichts von deinem Reader, damit kannst du auch keine Felder des Readers als Member angeben. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Query two fields into one combo box
    ... A combobox won't display both in the textbox window, ... To display the other column after the selection, place a textbox next to the ...
    (microsoft.public.access.queries)
  • Re: newbie help for winform combo box needed
    ... You can create your own ListItem class or just put "30" and override the drawing algorithm to display the item text + " days". ... public string value1; ... The ComboBox will call ToString to determine what to display. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Combo box.. need help
    ... <<Change the choices in the combobox to something like the number or topic ... Code the AfterUpdate ... then displays the question in the textbox. ... >> event of the combobox to display the question in the textbox. ...
    (microsoft.public.access.formscoding)

Loading