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
(adsbygoogle = window.adsbygoogle || []).push({});
03-18-2015, 04:17 PM #2
Default Avatar
Oneup
Guest
Originally posted by seanhellen View Post
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


You can either make a database or go basic and make a bunch of arrays. Then loop through the arrays to add the items to the combo boxes.
03-18-2015, 06:06 PM #3
seanhellen
Are you high?
Originally posted by 1UP View Post
You can either make a database or go basic and make a bunch of arrays. Then loop through the arrays to add the items to the combo boxes.


Yeah. I ended up using the addrange function. Still a pain but not as much as the add function lol Happy

Whilst im at it...is there a way to add to the range permenantly?
For example if i missed a suzuki gsxr1000 and didnt realise, could i have make/model textboxes and a button to add it to the range and for it to actually stay there forever?
03-19-2015, 05:12 AM #4
Default Avatar
Oneup
Guest
Originally posted by seanhellen View Post
Yeah. I ended up using the addrange function. Still a pain but not as much as the add function lol Happy

Whilst im at it...is there a way to add to the range permenantly?
For example if i missed a suzuki gsxr1000 and didnt realise, could i have make/model textboxes and a button to add it to the range and for it to actually stay there forever?

You would have to load that list from a file then at that point because you would need to save any changes you make if you do that. Otherwise if you don't it will be lost when the program exits.
03-19-2015, 05:48 AM #5
seanhellen
Are you high?
Originally posted by 1UP View Post
You would have to load that list from a file then at that point because you would need to save any changes you make if you do that. Otherwise if you don't it will be lost when the program exits.


Ah.That makes sense. I think I have seen that in various rtm tools. How could I do this? Im assuming it exports to a text file?
03-19-2015, 02:10 PM #6
Default Avatar
Oneup
Guest
Originally posted by seanhellen View Post
Ah.That makes sense. I think I have seen that in various rtm tools. How could I do this? Im assuming it exports to a text file?


Actually you could probably use the settings file. Granted it's not optimal, it's generated automatically and all you have to do is make a variable in it and set it in code.

The only downside is if you were to move the program the setting file is wiped.
03-20-2015, 05:35 AM #7
jagex
Gym leader
"so that I can select Suzuki (eg) in combobox1 and it will populate combobox2 with Suzuki Models"

If im understanding that correctly You can use a Lambda expression alongside a list.

Example:

List<string> Models = new List<String>();

Models.Where(x => x.Contains(combobox1.SelectedText);

So like this:

    
List<string> vehicle = new List<string>
{
"Ford",
"Honda",
"Chrysler"
};

var vName = vehicle.Where(v => v.Contains(comboBox1.Text));

foreach(var v in vName)
{
comboBox2.Items.Add(v);
}


A quick an easy way would be to put all the models in a textfile. You can have it formatted like this"

Honda, (Model)
Suzuki, (Model)
Suzuki, (Model)
Chrysler, (Model)

add all the files to a list
create another list equaling to the lambda expression
then run a for/foreach loop to add all the models from the list to the combo box

If you don't want the vehicle name you can do something like .indexOf(',', + 1); That would add only the letters after the comma.

Looks like you already solved it though!
03-20-2015, 07:35 AM #8
seanhellen
Are you high?
Originally posted by 1UP
snip


Originally posted by jagex
snip



Thanks guys. I will have a play once i get home (on hols atm) in a few days.

I am not familiar with lamda expressions...would it be possible to link a txt file to the model combobox(create many txt files - suzuki models.txt, honda models.txt etc)...or is that what the lamda expression does?

Or...Could i put all models in 1 txt file seperated somehow? I got too many things to think about now haha Happy
03-20-2015, 05:01 PM #9
jagex
Gym leader
Originally posted by seanhellen View Post
Thanks guys. I will have a play once i get home (on hols atm) in a few days.

I am not familiar with lamda expressions...would it be possible to link a txt file to the model combobox(create many txt files - suzuki models.txt, honda models.txt etc)...or is that what the lamda expression does?

Or...Could i put all models in 1 txt file seperated somehow? I got too many things to think about now haha Happy


Just put them all in one text file in this format and add it to a list

"CarName","Model"
"CarName","Model"
"CarName","Model"
"CarName","Model"
"CarName","Model"
03-20-2015, 05:17 PM #10
seanhellen
Are you high?
Not sure why i cant edit my post...but hey ho. So after a quick search (admittedly i should have done that 1st) could i put;

Models.Items.AddRange(File.ReadAllLines(models.txt))

And add them to a txt file by using;

File.AppendAllLines(File, new string[] { TextBox.Text }); }

Something like this?

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo