16,004,653 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 14351839 (Top 19 by date)
Member 14351839
3-May-19 17:53pm
View
Did this succesfully clones name and list?
public class Student : ICloneable
{
public List<int> Scores = new List<int>();
public string Name
{ get; set; }
public object Clone()
{
Student obj2 = new Student();
obj2.Scores = this.Scores;
obj2.Name = this.Name;
return obj2;
}
Member 14351839
3-May-19 17:51pm
View
Is this more in the right direction?
public class Student : ICloneable
{
public List<int> Scores = new List<int>();
public string Name
{ get; set; }
public object Clone()
{
Student obj2 = new Student();
obj2.Scores = this.Scores;
obj2.Name = this.Name;
return obj2;
}
Member 14351839
3-May-19 17:35pm
View
Yeah, quite lost. So, I should create an entire new Student object and clone it? How do I implement it to where the form only updates on the ok button event? I don't understand how the clone causes that.
Member 14351839
2-May-19 18:08pm
View
But Clone() is a string method used to clone the string object? So your saying in my case since my classes contain instances I need to build new instances? Guess I'm confused on why I can clone instances.
Member 14351839
1-May-19 19:24pm
View
Yeah, I figured it automatically stored the index based on my selection. I still need to add lots of error checking, but I'm glad we got this working. I've been stuck for days! lol thanks again
Member 14351839
1-May-19 19:10pm
View
That seemed to fix it. It's now
private void students_SelectedIndexChanged_1(object sender, EventArgs e)
{
_selectedIndex = students.SelectedIndex;
if (_selectedIndex > -1)
{
Student student = GetStudent(_selectedIndex); //select index from list
Student students = GetStudent(_selectedIndex); //select index from list
ScoreTotalTextBox.Text = student.GetScoreTotal().ToString(); //show Score Total to box
ScoreCountTextBox.Text = student.GetScoreCount().ToString(); //show Score Count to box
ScoreAverageTextBox.Text = student.GetScoreAverage().ToString(); //show Score Average to box
}
}
Member 14351839
1-May-19 18:59pm
View
How would I do that? I went here https://stackoverflow.com/questions/21327931/get-the-index-of-item-selected-in-listview and added the if statement, but to no avail.
Member 14351839
1-May-19 18:44pm
View
What do you mean by this? I tried calling it in my GetProduct method, but that did not work.
Member 14351839
1-May-19 18:39pm
View
I've added
private void students_SelectedIndexChanged_1(object sender, EventArgs e)
{
_selectedIndex = students.SelectedIndex;
Student student = GetStudent(_selectedIndex); //select index from list
ScoreTotalTextBox.Text = student.GetScoreTotal().ToString(); //show Score Total to box
ScoreCountTextBox.Text = student.GetScoreCount().ToString(); //show Score Count to box
ScoreAverageTextBox.Text = student.GetScoreAverage().ToString(); //show Score Average to box
}
and created the variable private int _selectedIndex; within the same class, but same error.
Member 14351839
1-May-19 18:34pm
View
I believe I've stored the SelectionIndex, but still receiving the same error.
Member 14351839
1-May-19 18:26pm
View
Guess I'm confused on where to set the index and how to call it.
Member 14351839
1-May-19 18:25pm
View
It takes me to the method directly above. If my logic is correct then the first line "Student student = GetStudent(students.SelectedIndex);" selects index from list I've created in the student class and within the student class I declared
public int GetScoreAt(int index)
{
return (int)studentList[index];
}
Member 14351839
1-May-19 18:03pm
View
I changed
private void students_SelectedIndexChanged_1(object sender, EventArgs e)
{
_selectedIndex = students.SelectedIndex;
Student student = GetStudent(_selectedIndex); //select index from list
ScoreTotalTextBox.Text = student.GetScoreTotal().ToString(); //show Score Total to box
ScoreCountTextBox.Text = student.GetScoreCount().ToString(); //show Score Count to box
ScoreAverageTextBox.Text = student.GetScoreAverage().ToString(); //show Score Average to box
}
and also changed the UpdateStudent method, but am still receiving the same error.
Member 14351839
1-May-19 17:50pm
View
Deleted
Have I not already done this?
Member 14351839
1-May-19 17:37pm
View
Any chance you could try and fix my solution? I'm not sure how to set the index to a local variable when the selection changes. I've been stuck at this part for a coupel days.
Member 14351839
1-May-19 17:25pm
View
So why exactly is out of range though? So, I should store the index in a variable within the update form?
Member 14351839
1-May-19 17:16pm
View
GetStudent(int id) UpdateStudent = Student student = GetStudent(originalIndex);
Member 14351839
1-May-19 17:12pm
View
I'm not sure how to explain. I attached my source code so you can see the exact issue. Going to keep working at it.
Member 14351839
1-May-19 17:08pm
View
I added the UpdateStuent method and because I'm entering an integer and I have it set as an integer?
Show More