I have a listbox which is currently reading fields from my database. I would like to be able to store each individual values that I am reading in as strings and ints. There will four field types, these are Surname, Forename, EmployeeID, PaymentDate. How do I split and store the selected item of combined fields as separate variables.
foreach (DataRow dr in dsEmployeePayment.Tables["EmployeePayment"].Rows)
{
lstPaymentID_Edit.Items.Add(
dr["Surname"].ToString() + ", "
+ dr["Forename"] + ", "
+ dr["EmployeeID"].ToString() + ", "
+ dr["PaymentDate"].ToString());
}
Consider creating an object for the items you are adding to the
ListBox
.Your class will contain all the fields in the correct types. The
ListBox
will callToString
on your item, and display it in the same fashion as you do now.The
DataRow
processing would happen like this:The real magic happens when you do something with the selected item: