2 Replies - 615 Views - Last Post: 21 August 2009 - 08:06 PM Rate Topic: -----

#1 timcamper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 22-July 09

richtextbox does not show complete results

Post icon  Posted 20 August 2009 - 08:39 PM

I don't see the results I expect in my richTextBox1.
Messagebox.show does give me what I should see.
But the richtextbox just shows the last player added to the list named PlayerName.

See Code:

private void btnPlayerName_Click(object sender, EventArgs e)		 {				
 for (int i = 0; i < PlayerName.Count; i++)
   {
	richTextBox1.Text = ("Player " + (i + 1) + " is " + PlayerName[i] + "\n");
MessageBox.Show(" Player " + (i + 1) + " is " + PlayerName[i]); // works fine
}
}


Each player is added to PlayerName list using a separate button for each.
Any help would be appreciated.

See button code:

private void btnTimCamper_Click(object sender, EventArgs e)		 
{
 PlayerName.Add("Tim Camper");			 btnTimCamper.BackColor = Color.LightCyan;			 btnTimCamper.Enabled = false;
}
private void btnAlFoster_Click(object sender, EventArgs e)		 
{
 PlayerName.Add("Al Foster");
btnAlFoster.BackColor = Color.LightCyan;			 btnAlFoster.Enabled = false;
}
private void btnRickHall_Click(object sender, EventArgs e)		 
{
 PlayerName.Add("Rick Hall");
btnRickHall.BackColor = Color.LightCyan;			 btnRickHall.Enabled = false;
}

Thanks - Tim

This post has been edited by timcamper: 20 August 2009 - 08:46 PM


Is This A Good Question/Topic? 0
  • +

Replies To: richtextbox does not show complete results

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: richtextbox does not show complete results

Posted 20 August 2009 - 09:29 PM

You are replacing the text in RTB each time. You should append the text instead so change this:
	richTextBox1.Text = ("Player " + (i + 1) + " is " + PlayerName[i] + "\n");



to this:
	// add + sign
	richTextBox1.Text += ("Player " + (i + 1) + " is " + PlayerName[i] + "\n");


Was This Post Helpful? 0
  • +
  • -

#3 timcamper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 22-July 09

Re: richtextbox does not show complete results

Posted 21 August 2009 - 08:06 PM

janne_panne;

Thanks for the help. I appreciate your help.
+= (the append fixed it)

Tim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1