Abdu Abdul

Abdu Abdul

  • 1.3k
  • 409
  • 15.4k

Change the color of text in richtextbox uisng string builder

Mar 14 2021 10:56 PM
Please am looking for away to change the color of text retrieved from database(sql server) using string builder, I have tried several methods but did not work, can anyone help me out.
  1. SqlCommand cmd= new SqlCommand("SELECT * FROM [Box] where item=@item", connect);  
  2. cmd.Parameters.AddWithValue("@item", item.Text);  
  3. StringBuilder resp = new StringBuilder();  
  4. SqlDataReader cmd_reader = cmd.ExecuteReader();  
  5. item.Text = "";  
  6. while (cmd_reader.Read())  
  7. {  
  8. respond.SelectionColor = Color.Red;  
  9. resp.Append(cmd_reader.GetString(6)).Append(Environment.NewLine);  
  10. respond.SelectionColor = Color.Green;  
  11. resp.Append(cmd_reader.GetString(7)).Append(Environment.NewLine);  
  12. }  
  13. item.Text = resp.ToString();  
is retrieving fine from the database but I want to change the colors of each line..

Answers (2)