3

I have a CSV file which holds various items. Some of these items I put into a combobox. How can I put a newline and/or tab in the CSV file so it will show up as a newline/tab inside the combobox? I have tried \t and \n but it just shows those in the combobox.

Csharp
  • 2,916
  • 16
  • 50
  • 77

1 Answers1

2

The base ComboBox doesn't support special characters like this for its display, they will simply be ignored. If you need this type of functionality you'll need to override the OnDrawItem method and draw those items on your own - I do not recommend this. Another option would be to use a more advanced ComboBox from a company like Telerik or Infragistics.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • 1
    This is mostly right. You probably don't want to override `OnPaint` because you don't want to take *all* of the drawing into your own hands. That would include things like the drop-down arrow that are best left to be painted by the system. Fortunately, the ComboBox control was explicitly designed to support owner-draw, which lets you take *some* but not all of the drawing into your own hands. In this case, you want to override `OnDrawItem`. I wrote up a very detailed answer [here](http://stackoverflow.com/a/15516029/366904) in response to a challenge that this could not be done in WinForms. – Cody Gray - on strike Jul 10 '13 at 19:22
  • @CodyGray, fantastic correction! Thank you very much. I'll edit the answer. Oh, and it can be done, I've done it as well. I'm going to jump over and have a look at your answer! – Mike Perrenoud Jul 10 '13 at 19:25