Hi,
I have a windows form with a listbox control. My code all works correctly
when deleting an item from the listbox except the last item. I get the
following message when trying to delete the last item:-
Specified argument was out of the range of valid values. Parameter name:
'64' is not a valid value for 'Value'.
The 64 reduces depending on how many listbox items are displayed.
Also (related) when deleting the last and only item from the listbox, the
error message changes to:
Specified argument was out of the range of valid values. Parameter name: '0'
is not a valid value for 'Value'.
My code is
private void _DoDelUser()
{
// Prompt the user first.
if (MessageBox.Show(this, "This will delete the selected user - continue?",
this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) !=
DialogResult.OK)
return;
// Get the current user index.
int userIndex = m_listBoxUsers.SelectedIndex;
// Should we ignore the the event?
if (userIndex == -1)
return;
// Get the identifier.
int userID = (Int32)m_userTable.Rows[userIndex]["user_id"];
// Delete the user.
UserManager.Delete(userID);
// Get the GUI state.
int index = m_listBoxUsers.SelectedIndex;
// Update the tables
m_userTable = UserManager.FindAll().Tables[0];
// Bind the GUI to the tables.
m_listBoxUsers.DataSource = m_userTable;
m_listBoxUsers.DisplayMember = "user_name";
m_listBoxUsers.SelectedIndex = index;
} // End _DoDelUser()
Thanks in advance and King Regards