当用户单击基于姓氏或程序的搜索按钮时,我需要在列表框中列出结果。结果将从一个外部访问文件中读取(连接成功)。
我已经定义:
Name of List Box: lstResultListBox
Name of Text Box: LastNameProgramTextBox
Name of Search Button: SearchButton
Radio button 1: byLastNameRadioButton
Radio button 2: byProgramRadioButton
Clear Button: ClearButton
我没有在此处提供数据库表。
Form1.cs:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'StudentsDataSet.Student' table. You can move, or remove it, as needed.
this.studentsTableAdapter.Fill(this.StudentsDataSet.Student);
}
private void Search_Click(object sender, EventArgs e)
{
var students =
from s in this.StudentsDataSet.Student
where s.LastName == LastNameProgramTextBox.Text
where s.ProgramName == LastNameProgramTextBox.Text
select s;
foreach (var s in students)
{
lstResultListBox.Items.Add(s.LastName + ", " + s.FirstName);
}
}
private void lstResultListBox_SelectedIndexChanged(object sender, EventArgs e)
{
LastNameProgramTextBox.Text = lstResultListBox.SelectedItem.ToString();
}
我无法搜索或清除按钮!我尝试了Search_Click和SelectedIndexChanged,但无法弄清缺少的内容。这是我第一次在C#Windows窗体中搜索。 我已经正确定义了列表框,文本框,搜索按钮,清除按钮和单选按钮的名称。