0

I'm pulling data from an API and concatenating it into a string that I'm formatting in every iteration.

Here is the piece of code where I format a string and add it to the listbox:

rezultat = String.Format("{0} {1} {2}", stevilka.PadRight(7), smer.PadRight(25), prihodi);
rezultati.Items.Add(rezultat);

Where rezultati is the name of the listbox and stevilka, smer, prihodi are the columns I am trying to align in a listbox. The current output looks like this:

output

I'm using a mono-font (courier new) but I guess there is something else I'm missing out?

7
  • 1
    That font doesn't look like courier new to be honest Commented Jan 3, 2016 at 11:44
  • @rene I have this under ListBox properties: FontFamily="Courier New", so It should be Courier New? Commented Jan 3, 2016 at 11:50
  • Well it should but as one can plainly see it isn't. Commented Jan 3, 2016 at 12:45
  • @TaW any reason why that could be happening? Commented Jan 3, 2016 at 12:57
  • No. A few ideas: Put a breakpoint to see what the currently assigned Font is. Also search for any spot where you do a Font assignment. I assume that the Font is available? Try using Consolas. Commented Jan 3, 2016 at 13:38

1 Answer 1

1

I am not very familiar to the UWP platform, but if you would populate a ListBox in WPF like you did, string.Format"{0} {1} {2}" alone does in no way guarantee that each item and its columns are aligned to one another.

I think there aren't any controls that implement the "column behavior" per default, but maybe you should have a look at the GridView or ListView controls.

Guidelines for list view and grid view

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.