Post: Comboboxes & Lists
03-18-2015, 09:36 AM #1
seanhellen
Are you high?
(adsbygoogle = window.adsbygoogle || []).push({}); Hey everyone - I was wondering what is is the easiest way to make a few lists, then depending on the option selected in combobox1, it will populate combobox2.

What I have is 2 comboboxes - Make and Model. I know I can add stuff by typing

    comobobox1.Items.Add("Suzuki");


but doing that for every Make and model is gonna be a ballache. So I was wondering if someone knew of a way I can make some lists eg;-

-Make (Suzuki, Honda, etc)
-Suzuki Models
-Honda Models
-etc

so that I can select Suzuki (eg) in combobox1 and it will populate combobox2 with Suzuki Models
03-21-2015, 07:48 PM #20
seanhellen
Are you high?
Thats what i tried, but didnt get very far lol. Went on new and chose data and selected the database and then a wizard came up that confused me so i gave up lol
03-21-2015, 08:56 PM #21
jagex
Gym leader
lols, ill try working on this project and see if I can do anything with just at text file.
03-21-2015, 09:26 PM #22
seanhellen
Are you high?
Lol. Appreciated. As far as i can tell the file.appendalllines thing adds lines to a txt file whereas file.writealllines or writealltext overwrites the whole doc...rendering it useless in this case which is why i thought readalllines to commit the file contents to memory then appendalllines to add then save the file...thats my logic anyways lol
03-21-2015, 10:11 PM #23
jagex
Gym leader
Np

I have this so far and it seems to work as of now, still got to clean and fix it up

    
private void Car_Models()
{
string[] cars = carInformation.Vehicles_Models().Split(';'Winky Winky;

for (int i = 0; i < cars.Length; i++)
{
string c = cars[i];


if (c.Contains(comboBox1.Text))
{
string model = c.Substring(c.IndexOf(','Winky Winky + 1);
comboBox2.Items.Add(model);
}
}
}


    namespace Car_Models
{
class CarInformation
{
public string Vehicles_Models()
{
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Models.txt";
string models= "";

if (File.Exists(filePath))
{
using (StreamReader sr = new StreamReader(filePath))
{
models = sr.ReadToEnd();


}
}
return models;
}
}
}


Hopefully this is what you were looking for :p
You must login or register to view this content.
You must login or register to view this content.

Textfile has to be formatted like this, but you can change it:
Suzuki,Aerio;
Suzuki,Equator;
Honda,Fit;
Honda,Civic Coupe Si;
Honda,Civic Sedan;
Last edited by jagex ; 03-21-2015 at 10:25 PM.
03-21-2015, 10:31 PM #24
seanhellen
Are you high?
Wow. Thanks for that jagex. Very Helpful Smile

Now i need 2 textboxes (or 1 if you can manage it) so that you can permenantly add say a Honda Jazz in the list
Last edited by seanhellen ; 03-21-2015 at 10:35 PM.
03-22-2015, 12:29 AM #25
jagex
Gym leader
Ok, I will work on it tomorrow
03-22-2015, 08:38 PM #26
jagex
Gym leader
Try doing it yourself.

Add the vehicle you want added to the same list/array that you fetched from the textfile and just write them all to the textfile.
03-23-2015, 07:02 AM #27
seanhellen
Are you high?
Ok. I will have a go tomorrow. Last hol day today so will have a crack before work. Thanks for your help so far Smile
03-24-2015, 10:27 AM #28
seanhellen
Are you high?
Originally posted by jagex View Post
snip


Ok - I have had a crack at this. For some reason vs didn't like your string[] cars = CarInformation.Vehicles_Models().Split(';'Winky Winky; so I went on a bit of a hunt and have ended up with this;

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "Suzuki")
{
comboBox2.Items.Clear();
string[] lineOfContents = File.ReadAllLines("Models.txt");
foreach (var line in lineOfContents)
{
string[] tokens = line.Split(','Winky Winky;
comboBox2.Items.Add(tokens[1]);
}
}
}


I have a txt file with makes and models in the same file called "Models.txt" so;

    
Suzuki,gsxr 1000
Suzuki,gsxr 750
Suzuki,gsxr 600
Honda,cbr 600 rr
Honda,cbr 600 f
Honda,cbr 125


(they are bikes) and with the above code, it gives me the list, without the make which is fine, but I need to filter out the unneeded makes and models - so when I select Suzuki in cb1, cb2 will fill with the gsxr range, and if I select Honda in cb1, cb2 will fill with the cbr range.

If we could get that far, I think we will be groovy. Happy

I tried putting an if statement with token[0] == "Suzuki" but it wasn't having it :confused:

Then (as far as adding to the range goes) all I have to do (in my mind) is add a button and 2 texboxes and add the following to the button;

    
file.appendalltext("Models.txt", environment.newline + textbox1.text + "," + textbox2.text)


but I can figure that out later :p

But yeah, any help with the 1st bit would be great Smile

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo