Yuvraj Jambhle

Yuvraj Jambhle

  • NA
  • 93
  • 8.4k

how to show checkbox list items in one line using C#

Sep 17 2020 7:58 AM
I have written a code for the same.
  1. private void btnColumnWrite_Click(object sender, EventArgs e)  
  2. {  
  3. string s = "";  
  4. for (int i = 0; i < checkedListBox1.Items.Count; i++)  
  5. {  
  6. if(checkedListBox1.GetItemChecked(i))  
  7. {  
  8. s += checkedListBox1.Items[i] +",";  
  9. }  
  10. }  
  11. StreamWriter SwriteData = new StreamWriter(@"C:\Users\user\Desktop\ReportTmplate\Test.txt");  
  12. SwriteData.WriteLine("(" + s + ")");  
  13. SwriteData.Close();  
  14. }  
When I execute this above code I got solution like wise : T1,T2,T3,T4,
 
But I want this like - T1,T2,T3,T4
 
I want to remove the last comma "," Symbol which is coming after T4 (Means last item selection), So please guide me on how to avoid this last ",".

Answers (4)