我如何将对象(包括名称和 ID)从列表框移动到另一个列表框并保存?我写了这个:
if (lstActivity.SelectedIndex != -1)
{
int intSelectedIndex = lstActivity.SelectedIndex;
if (intSelectedIndex >= 0)
{
listbox.Items.Add(((Parking_Services.Activity)lstActivity.SelectedItem).ActivityName);
lstActivity.Items.RemoveAt(intSelectedIndex);
}
}
它可以工作,但是当我想保存它时(单击按钮后),它会出现异常:“无法将 syste.string 转换为(Parking_Services.Activity)。”
private void btnSave_Click(object sender, EventArgs e)
{
int intActivityID;
Parking_Services.Service1 ii = new Parking_Services.Service1();
for (int i = 0; i <= listbox.Items.Count; i++) //save item from listbox is wrong
{
intActivityID = ((Parking_Services.Activity)listbox.Items[i]).ActivityID;
string strMessage = ii.AllowUserActivityByType(intUserTypeID, intActivityID, FrmLogin.intUserId);
}