Re: help - populating a combox box from a text file and updating a listbox automatically
- From: "Morten Wennevik" <MortenWennevik@xxxxxxxxxxx>
- Date: Tue, 07 Nov 2006 13:34:02 +0100
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]
.
- References:
- help - populating a combox box from a text file and updating a listbox automatically
- From: CCLeasing
- Re: help - populating a combox box from a text file and updating a listbox automatically
- From: CCLeasing
- Re: help - populating a combox box from a text file and updating a listbox automatically
- From: Morten Wennevik
- Re: help - populating a combox box from a text file and updating a listbox automatically
- From: CCLeasing
- Re: help - populating a combox box from a text file and updating a listbox automatically
- From: CCLeasing
- help - populating a combox box from a text file and updating a listbox automatically
- Prev by Date: Re: Propagation of events from custom control to Form
- Next by Date: Type alias in C#
- Previous by thread: Re: help - populating a combox box from a text file and updating a listbox automatically
- Next by thread: help - populating a combox box from a text file and updating a textbox automatically
- Index(es):
Relevant Pages
|
Loading