[英]is never assigned to, and will always have its default value
Im trying to select a name from a dropdown list created from a database. 我正在尝试从数据库创建的下拉列表中选择一个名称。 I cant seem to get the mane to assign.
我似乎无法分配鬃毛。
When I click the select button it does not carry the persons name in the comboBox1 through to me next lot of code. 当我单击选择按钮时,comboBox1中并没有携带人员姓名,而是向我发送下一批代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Sql;
namespace GlidingLogsGUI2
{
public partial class InstructorSelectionForm : Form
{
List<Person> instructors = new List<Person>();
Person selectedPerson;
public InstructorSelectionForm()
{
InitializeComponent();
this.TopMost = true;
List<Person> instructors = new List<Person>();
OleDbCommand com = new OleDbCommand("SELECT * FROM Personnel WHERE [Current?] = TRUE AND [Position] = ?", Program.DB_CONNECTION);
com.Parameters.Add(new OleDbParameter("", PositionIDs.INSTRUCTOR));
OleDbDataReader dr = com.ExecuteReader();
while (dr.Read())
{
try
{
instructors.Add(new Person(dr));
}
catch
{
}
}
foreach (Person a in instructors)
comboBox1.Items.Add(a.FirstName + " " + a.Surname);
}
private void Selectbutton_Click_1(object sender, EventArgs e)
{
if (selectedPerson == null)
{
MessageBox.Show("A person must be selected first");
return;
}
new F5363(selectedPerson);
}
private void CancelButton_Click_1(object sender, EventArgs e)
{
this.Close();
}
private void InstructorSelectForm_Load(object sender, EventArgs e)
{
}
}
}
You're declaring selectedPerson, but never setting it anywhere. 您在声明selectedPerson,但不要在任何地方设置它。 I suspect what you want to do is to remove the current declaration of selectedPerson and change the click event to something similar to;
我怀疑您要删除当前的selectedPerson声明,并将click事件更改为类似于以下内容的方法:
private void Selectbutton_Click_1(object sender, EventArgs e)
{
Person selectedPerson = comboBox1.SelectedItem as Person;
if (selectedPerson == null)
{
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.