Click to See Complete Forum and Search --> : ArgumentOutOfRangeException


pre_wreck
April 9th, 2007, 11:23 PM
Hi Guru's,

Kindly please help.

I have this error whenever I wan't to bind the item from the list box to text box.

An unhandled exception of type 'System.ArgumentOutOfRangeException', occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid values.


I have a listview and textboxes in my form.

Scenario:

All I need to do is when I select and item from the listview it will reflect those into my textbox.

What are the possible resolution to this?

Kindly please help.

I have here my sample code.


RegistrationSystem.FillDetails_Students studentDetails = mdlProd.GetStudentsDetails((int.Parse(lvStudents.SelectedItems[0].Text)));

if ( studentDetails == null )
{
MessageBox.Show ( "Couldn't retrieve the object for the selected row.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
return;
}


txtStudID.Text = studentDetails.StudID.ToString();
txtStudNo.Text = studentDetails.StudentNum;
txtName.Text = studentDetails.Name;
txtDegree.Text = studentDetails.Degree;

aniskhan
April 9th, 2007, 11:55 PM
Use selectedItems collection after checking the count property.
if (ListView1.SelectedItems.Count > 0)
{
//do yor code here
}

pre_wreck
April 10th, 2007, 01:48 AM
Thanks aniskan, it works great! :thumb: