このプロジェクトは、ユーザーがコースを選択できるようにするためのダイアログボックスを開きます。それが生み出す出力は、私には1つのコースから選択できるだけです。どのようにすべてのコースを表示するコースクラスを取得できますか?WPFアプリケーションで複数の値を出力するにはどうすればよいですか?
これは、メインウィンドウのファイルです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CreateClassesObjs
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Course choice;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Course course1 = new Course();
Course course2 = new Course();
Course course3 = new Course();
Course course4 = new Course();
Course course5 = new Course();
Course course6 = new Course();
Course course7 = new Course();
course1.setName("IT 145");
course2.setName("IT 200");
course3.setName("IT 201");
course4.setName("IT 270");
course5.setName("IT 315");
course6.setName("IT 328");
course7.setName("IT 330");
this.comboBox.Items.Add(course1);
this.comboBox.Items.Add(course2);
this.comboBox.Items.Add(course3);
this.comboBox.Items.Add(course4);
this.comboBox.Items.Add(course5);
this.comboBox.Items.Add(course6);
this.comboBox.Items.Add(course7);
}
private void button_Click(object sender, RoutedEventArgs e)
{
choice = (Course)(this.comboBox.SelectedItem);
this.listBox.Items.Add(choice);
}
}
}
そして、これが私のファイルです。
namespace CreateClassesObjs
{
internal class Course
{
static string name;
public Course()
{
}
public string setName(string choice)
{
name = choice;
return name.ToString();
}
/*
public string retrieveName(string choice)
{
name = choice;
return name.setName();
}
*/
public override string ToString()
{
return name;
}
}
}
それは最後の値だけを印刷しています。これらのすべてを印刷するはずです。
course1.setName("IT 145");
course2.setName("IT 200");
course3.setName("IT 201");
course4.setName("IT 270");
course5.setName("IT 315");
course6.setName("IT 328");
course7.setName("IT 330");
ToStringはすべての前の文字列を取得することになっています。
助けてくれてありがとうございますが、私はそのファイルを2番目のものだけで編集するはずがありません。 – user2803555