c# Display the data in the List view
Posted
by Kumu
on Stack Overflow
See other posts from Stack Overflow
or by Kumu
Published on 2010-04-24T12:58:34Z
Indexed on
2010/04/24
13:03 UTC
Read the original article
Hit count: 183
c#
private void displayResultsButton_Click(object sender, EventArgs e)
{
gameResultsListView.Items.Clear();
//foreach (Game game in footballLeagueDatabase.games)
//{
ListViewItem row = new ListViewItem();
row.SubItems.Add(game.HomeTeam.ToString());
row.SubItems.Add(game.HomeScore.ToString());
row.SubItems.Add(game.AwayTeam.ToString());
row.SubItems.Add(game.AwayScore.ToString());
gameResultsListView.Items.Add(row);
// }
//footballLeagueDatabase.games.Sort();
}
}
}
This is the display button and the following code describes the add button.
private void addGameButton_Click(object sender, EventArgs e)
{
if ((homeTeamTxt.Text.Length) == 0)
MessageBox.Show("You must enter a Home Team");
else if (homeScoreUpDown.Maximum <= 9 && homeScoreUpDown.Minimum >= 0)
MessageBox.Show("You must enter one digit between 0 and 9");
else if ((awayTeamTxt.Text.Length) == 0)
MessageBox.Show("You must enter a Away Team");
else if (awayScoreUpDown.Maximum <= 9 && awayScoreUpDown.Minimum >= 0)
MessageBox.Show("You must enter one digit between 0 to 9");
else
{
//checkGameInputFields();
game = new Game(homeTeamTxt.Text, int.Parse(homeScoreUpDown.Value.ToString()), awayTeamTxt.Text, int.Parse(awayScoreUpDown.Value.ToString()));
MessageBox.Show("Home Team" + 't' + homeTeamTxt.Text + "Away Team" + awayTeamTxt.Text + "created");
footballLeagueDatabase.AddGame(game);
//clearCreateStudentInputFields();
}
}
I need to insert data into the above text field and Numeric up down control and display them in the list view. But I dont know How to do it, because when I press the button "Display Results" it displays the error message.
If you know how can I display the data in the list view, please let me know.This is the first time I am using List view.
© Stack Overflow or respective owner