-
ArrayList 'Index out of range'
Hi Pros,
My problem this time is:
I have a ListBox and an ArrayList, containing a class User as elements of the ArrayList.
'in Declarations
Private Users As New ArrayList() 'Array of all users
Private dbRow as OleDb.DataRow
'So I load all items from the DB:
For Each dbRow In dbDataSet.Tables("Users").Rows
Users.Add(New User(dbRow("UserName"), _
dbRow("UserPass"), _
dbRow("FullName"), _
dbRow("Position"), _
dbRow("AccessLevel")))
Next dbRow
lstUsers.DataSource = Users
lstUsers.DisplayMember = "UserName"
'So far everithing is OK. But when I remove an item from the Users ...
Users.Remove(lstUsers.SelectedItem)
lstUsers.DataSource = Users
lstUsers.DisplayMember = "UserName" 'to show the changes in the ListBox
'...and it goes away from the ListBox, when I click an item in it an exception raises saying: "Index was out of range. Must be non-negative and less than the size of the collection." (in mscorlib.dll) and the pointer in the Dev. environment (text editor) points to the first line in the code:
Public Class frmUserAdmin
, which is not of much help. This happens after the lstUsers.SelectedIndexChanged event is completed.
Any ideas what I'm doing wrong and which index is out of range (i think the ArrayList's but how to check this index and it's setting)?
Thanks,
Miroslav St. Jeliaskoff
-
Re: ArrayList 'Index out of range'
One more thing I found out. When I remove the last element of the ArrayList then this exception occures. It doesn't metter which one is the last element.
Miroslav
"Miroslav St. Jeliaskoff" <miroslav@earthling.net> wrote in message news:3db03b07@tnews.web.devx.com...
Hi Pros,
My problem this time is:
I have a ListBox and an ArrayList, containing a class User as elements of the ArrayList.
'in Declarations
Private Users As New ArrayList() 'Array of all users
Private dbRow as OleDb.DataRow
'So I load all items from the DB:
For Each dbRow In dbDataSet.Tables("Users").Rows
Users.Add(New User(dbRow("UserName"), _
dbRow("UserPass"), _
dbRow("FullName"), _
dbRow("Position"), _
dbRow("AccessLevel")))
Next dbRow
lstUsers.DataSource = Users
lstUsers.DisplayMember = "UserName"
'So far everithing is OK. But when I remove an item from the Users ...
Users.Remove(lstUsers.SelectedItem)
lstUsers.DataSource = Users
lstUsers.DisplayMember = "UserName" 'to show the changes in the ListBox
'...and it goes away from the ListBox, when I click an item in it an exception raises saying: "Index was out of range. Must be non-negative and less than the size of the collection." (in mscorlib.dll) and the pointer in the Dev. environment (text editor) points to the first line in the code:
Public Class frmUserAdmin
, which is not of much help. This happens after the lstUsers.SelectedIndexChanged event is completed.
Any ideas what I'm doing wrong and which index is out of range (i think the ArrayList's but how to check this index and it's setting)?
Thanks,
Miroslav St. Jeliaskoff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks