Hello all,
I'm writing a program to keep track of my swim team's test set times. I would like to display the information in a table like form to edit all of the swimmers and times at once. I'm using this object:
public class TestSetDisplay : INotifyPropertyChanged
{
string testSetName;
string swimmerName;
List<Time> times;
Time average;
public event PropertyChangedEventHandler PropertyChanged;
public TestSetDisplay(Swimmer s, TestSet t)
{
testSetName = t.Name;
swimmerName = s.Name;
foreach (TestSet ts in s.TestSet)
{
if (ts.Name == testSetName)
{
times = ts.Times;
}
}
}
public Time Average
{
get { return average; }
//set { average = value; }
}
public string SwimmerName
{
get { return swimmerName; }
set { swimmerName = value;
this.NotifyPropertyChanged("SwimmerName");
}
}
public List<Time> TimeList
{
get { return times; }
set { times = value; }
}
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
You don't really need to know too much about the Swimmer and TestSet objects, I just get the names and the times for the test set out of those.
So here is my problem, I want to display a table in this form:
Name................time1............time2.................average
swimmer1......1:00.70..........1:01.65...............average of all the times
swimmer2........:58.54..........1:00.33
....
***How do I get each time from the List of times into the datagridview?
***Maybe a more simple question, how do I make a new column for each time in the datagridview?
Here is what I'm trying to do so far:
table = new DataTable("display");
DataColumn nameCol = new DataColumn("Swimmer Name");
nameCol.DataType = System.Type.GetType("System.String");
table.Columns.Add(nameCol);
// One column for each time
DataColumn timeCol;
for (int i = 0; i < theSet.Times.Count; i++)
{
string num = Convert.ToString(i + 1);
timeCol = new DataColumn(num);
timeCol.DataType = System.Type.GetType("System.String");
table.Columns.Add(timeCol);
}
// Make the Name column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["Swimmer Name"];
table.PrimaryKey = PrimaryKeyColumns;
DataRow row;// = new DataRow();
foreach (TestSetDisplay td in displayList)
{
row = table.NewRow();
row["Swimmer Name"] = td.SwimmerName;
int i = 1;
foreach (Time t in td.TimeList)
{
row[Convert.ToString(i)] = t;
i++;
}
table.Rows.Add(row);
}
dataGridView1.DataSource = displayList;
Please help!