2 Replies - 301 Views - Last Post: 07 February 2013 - 02:26 PM Rate Topic: -----

#1 DaiToBu  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 93
  • Joined: 17-March 12

String Format problem

Posted 07 February 2013 - 02:12 PM

Well I tried to return a string into the listbox, but the items doesn't align even.

This is my ToString, the three value is from getting value.
        public override string ToString()
        {
            return String.Format("{0,-25} {1,-7} {2,-1:F}", companyName, stock, date);
        }


Result on the listbox is
Publix         PUB   1/23/2003
Target Store      TS   1/23/2003



Is This A Good Question/Topic? 0
  • +

Replies To: String Format problem

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3574
  • View blog
  • Posts: 11,114
  • Joined: 05-May 12

Re: String Format problem

Posted 07 February 2013 - 02:23 PM

Is that really the output? There isn't close to 25 characters before the stock symbol. Is that just your exaggerated output for us?

Anyway, remember that the default font used is a proportional font rather than a fixed width font. So kerning happens and some strings will use up more or less space than others. If you want your columns to line up, I suggest using a ListView or DataGridView instead.
Was This Post Helpful? 0
  • +
  • -

#3 DaiToBu  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 93
  • Joined: 17-March 12

Re: String Format problem

Posted 07 February 2013 - 02:26 PM

Yeah that was how the output. I guess the problem with the view is font size and font type. Maybe I try to reverse the listbox to listview, but hopefully it easy to implement.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1