There is a ListBox . WinForm. It adds / deletes records. As a data source I use List<string> QuestionsList ; lbAnswers.DataSource = QuestionsList ;

How in this situation to make auto-numbering of lines of such a character. Ie in the output add the prefix in the form of numbers. enter image description here

Maybe what kind of event or need to be inherited from it and cut your logic to add write or can there be other options?

  • @AlexanderPetrov WinForms - gregor Nov.

1 answer 1

Found the Format event and it suits me.

 private void lbAnswers_Format(object sender, ListControlConvertEventArgs e) { Question ques = e.ListItem as Question; if (ques != null) { var items = (sender as ListControl).DataSource as IList<Question>; if (items != null) e.Value = items.IndexOf(ques) + 1 + ". " + ques.Text; } }