我有这样的表格:
我已经使用以下代码加载了第一个listBox。
MySqlConnection myconn = new MySqlConnection(connString);
DataTable dt = new DataTable();
string family = "SELECT respondentID, CONCAT(respondent.firstName, ' ', respondent.lastName, ' (', role, ')') AS Name FROM respondent, household WHERE household.householdID = 64";
MySqlCommand mycommand = new MySqlCommand(family, myconn);
MySqlDataAdapter da = new MySqlDataAdapter(mycommand);
da.Fill(dt);
listBox1.DataSource = dt;
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "respondentID";
现在如果我点击下面的特定按钮(基于屏幕截图), 必须将listBox1中的所选名称传输到listBox2,格式为:
John Doe - 受伤
Jane Doe - 失踪
我希望他们的ID也可以转移,所以如果我要保存所有内容,我只会调用他们的ID,但我无法从下面的代码转移其valueMember
class Person
{
private string _name;
private string _id;
Person(string name, string id, string remarks)
{
_name = name + " " + remarks;
_id = id;
}
public override string ToString()
{ return _name; }
public string id
{
get { return _id; }
}
public string name
{
get { return _name; }
}
}
请帮帮我。
这是每个按钮的代码:
foreach (var item in listBox1.SelectedItems)
{
listBox2.Items.Add(new Person( ((DataRowView)item)["Name"].ToString(), ((DataRowView)item)["respondentID"].ToString(), "Injured"));
}