I had question about the array in an other post and figure for the most part, but I honestly stuck on what do at the moment with my project because I can get my test scores to show up correctly, so I must be doing something wrong.
Can someone take a look and maybe point me in the correct direction again?
Student Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace maint_student_scores
{
public class student
{
public string name { get; set; }
public List<int> Scores = new List<int>();
public int scoreTotal()
{
int Total = 0;
foreach (int score in Scores)
{
Total += score;
}
return Total;
}
public static int averageAllStudents(List<student> Students)
{
int totalScores = 0; //total scores init. for students
int totalCount = 0; //total count of scores init. for all students
//our favor command foreach in an array
foreach (student s in Students)
{
foreach (int score in s.Scores)
{
totalScores += score;
totalCount++;
}
}
return totalScores / totalCount;
}
public int scoreCount()
{
return Scores.Count;
}
public void addScore(int Score)
{
Scores.Add(Score);
}
public void editScore(int Score, int index)
{
Scores.Remove(index);
Scores.Insert(index, Score);
}
public void deleteScore(int index)
{
Scores.Remove(index);
}
}
}
MainForm:
namespace maint_student_scores
{
public partial class maintain_student_scores : Form
{
List<student> Students;
public maintain_student_scores()
{
InitializeComponent();
}
private void maintain_student_scores_Load(object sender, EventArgs e)
{
Students = new List<student>(); //create our student list
Students = new List<student>(); // create the list
// add some items so we can see in the listview test on Form2
student s1 = new student();
s1.name = "George Carnegie";
s1.Scores.Add(100);
s1.Scores.Add(95);
Students.Add(s1);
student s2 = new student();
s2.name = "Bill Butler";
s2.Scores.Add(85);
s2.Scores.Add(79);
Students.Add(s2);
}
private void addBtn_Click(object sender, EventArgs e)
{
newstudent newStudentFrm = new newstudent(Students);
newStudentFrm.ShowDialog();
}
private void updateBtn_Click(object sender, EventArgs e)
{
scoreupdate scoreupdateFrm = new scoreupdate(Students);
scoreupdateFrm.ShowDialog();
}
private void deleteBtn_Click(object sender, EventArgs e)
{
}
private void exitBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void scoretotalTbox_TextChanged(object sender, EventArgs e)
{
}
}
}
NewStudentForm:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace maint_student_scores
{
public partial class newstudent : Form
{
List<student> Students;
public newstudent(List<student> Students)
{
InitializeComponent();
this.Students = Students;
}
private void cancelBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void newstudent_Load(object sender, EventArgs e)
{
}
private void addscoreBtn_Click(object sender, EventArgs e)
{
}
private void clearscoresBtn_Click(object sender, EventArgs e)
{
}
private void okBtn_Click(object sender, EventArgs e)
{
}
}
}
UpdateScoreForm:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace maint_student_scores
{
public partial class scoreupdate : Form
{
List<student> Students;
public scoreupdate(List<student> Students)
{
InitializeComponent();
this.Students = Students;
}
private void updatescores_Load(object sender, EventArgs e)
{
foreach (student s in Students)
scoreList.Items.Add(new ListViewItem(s.ToString()));
}
private void cancelBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void clearscoresBtn_Click(object sender, EventArgs e)
{
}
private void okBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void addBtn_Click(object sender, EventArgs e)
{
updatescores_add updateScoresAddFrm = new updatescores_add(Students);
updateScoresAddFrm.ShowDialog();
}
private void updateBtn_Click(object sender, EventArgs e)
{
updatescores_update updateScoresUpdateFrm = new updatescores_update(Students);
updateScoresUpdateFrm.ShowDialog();
}
}
}
and I have those two form but I won't post them because I'm pretty sure if I get pointed in the right direction I'll be able to see the light and understand those.
So couple questions I have:
1) Did I correctly add the test student data and why is it not showing up correctly (give me nothing but ListViewItem blah blah blah).
2) If you add a newstudent with the form and you click ok how do you save it to the array.
Those are mainly my two questions I'm not sure about how to do. I know the clearing is just selecting the index (one that currently selected) and doing the remove method.
Thanks for any help.