I have this code in the main window class where I declare some values to put in a ListForTesting list and make the tests appear in a combobox. Later there is another combobox that depends on the first on which I present you the code down bellow:
It may be worth to mention that I am completely new to C#. Only coded in VBA. I'm a mechanical engineer, not software :)
Main Window code
public MainWindow()
{
InitializeComponent();
grid_projectConfig.Visibility = Visibility.Collapsed;
grid_projectOverview.Visibility = Visibility.Collapsed;
grid_test.Visibility = Visibility.Collapsed;
grid_reports.Visibility = Visibility.Collapsed;
//ListForTesting holds the hardcoded set of tests and manoeuvres
List<HelpClass.TestID> ListForTesting = new List<HelpClass.TestID>();
//TestObject holds the test name, ID and all the manoeuvres related to it
HelpClass.TestID TestObject = new HelpClass.TestID();
TestObject.testName = "Steady State";
TestObject.ID = 0;
//Manoeuvre holds the manoeuvre name and its ID
TestObject.Manoeuvres = new List<HelpClass.ManoeuvresID>();
HelpClass.ManoeuvresID Manoeuvre = new HelpClass.ManoeuvresID();
Manoeuvre.manName = "30 kph";
Manoeuvre.manID = 0;
//add the Manoeuvre to the TestObject
TestObject.Manoeuvres.Add(Manoeuvre);
//create new Manoeuvre
Manoeuvre = new HelpClass.ManoeuvresID();
Manoeuvre.manName = "50 kph";
Manoeuvre.manID = 1;
TestObject.Manoeuvres.Add(Manoeuvre);
//add the TestObject to the ListForTesting
ListForTesting.Add(TestObject);
//display the tests in a combobox
combobox_testType.ItemsSource = ListForTesting.Select(t => t.testName);
}
Second combobox code
public void combobox_testType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
combobox_testType.ItemsSource = ListForTesting[1].Manoeuvres.Select(t => t.manName);
}
this last line of code does not work because it tells me that it does not exist in the current context.