TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hayden Meherg
NA
35
5.9k
How to update data in a listbox from another form?
May 1 2019 2:47 PM
I'm creating a program that maintains student scores. I've created a class called students that stores the data and displays it in a list box. Once the user clicks btnAdd a new form (frmAddStudent) loads that allows them to add the user by name and their scores and display it in the listbox in the main form. It also allows the update/delete functions. I can succesfully add students to the list and edit them, but when I press the ok button in the update students form I get the error,
"System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'". I know this means that the argument passed was out of range, but I'm not sure how. Any help is appreciated. Thanks! I've included my source code if you want a deeper look.
frmUpdateStudent.cs
private
void
UpdateButton_Click_1(
object
sender, EventArgs e)
//open update form for current student
{
Student Form1 =
new
Student();
Form1.Name = StudentName.Text;
parentForm.UpdateStudent(index, Form1);
Close();
}
Form1.cs
public
Student GetStudent(
int
id)
//Get student index
{
return
studentList[id];
}
Student.cs
public
class
Student
{
public
List<
int
> Scores =
new
List<
int
>();
public
string
Name
{
get
;
set
; }
public
bool
AddScore(
int
score)
{
try
{
Scores.Add(score);
}
catch
{
return
false
; }
return
true
;
}
public
List<
int
> GetScores()
{
return
Scores;
}
public
int
GetScoreAt(
int
index)
{
return
(
int
)Scores[index];
}
public
int
GetScoreTotal()
{
int
sum = 0;
foreach
(
int
score
in
Scores)
{
sum += score;
}
return
sum;
}
public
int
GetScoreCount()
{
return
Scores.Count;
}
public
int
GetScoreAverage()
{
return
GetScoreTotal() / GetScoreCount();
}
public
void
DestroyScores()
{
Scores =
new
List<
int
>();
}
Attachment:
MaintainStudentScores.zip
Reply
Answers (
2
)
I want to receive data from a gps device and want to show t
automatically open a combobox when value select from another