I have this form:
I have loaded the first listBox with the following codes.
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";
Now If i will click a particular button below (based on the screenshot), the selected name from listBox1 must be transferred to listBox2 with the format:
John Doe - Injured
Jane Doe - Missing
I want their IDs to be transferred as well so if I am going to save everything I will just call their IDs but I am unable to transfer its valueMember from the code below
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; }
}
}
Please help me.
This is the code for each button:
foreach (var item in listBox1.SelectedItems)
{
listBox2.Items.Add(new Person( ((DataRowView)item)["Name"].ToString(), ((DataRowView)item)["respondentID"].ToString(), "Injured"));
}