dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] List view spacing issues

  1. #1

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,346

    Resolved [RESOLVED] List view spacing issues

    I'm reading in a text file via StreamReader and at the same time loading a list view with the text line. The issue is the text file, even though fixed, is reformatting the spaces in it some how.



    You can see in the text file input how the data is evenly spaced. Then in the list view the lines are not spaced evenly based on the number of spaces in between text on the input. I want to load the list view so that it looks like the input.

    The distance between the name and "Y201", Y9555", etc. has different amounts of spaces between them. The column header says "Excel" but the input is a text file.

    Here is the code:

    sw.WriteLine(line)
    lv = New ListViewItem
    lv.Text = line
    ListView1.Items.Add(lv)

    Any suggestions?

    Input and list view:
    Attached Images Attached Images   
    Last edited by TysonLPrice; Jul 5th, 2017 at 01:36 PM.
    Please remember next time...elections matter!

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,244

    Re: List view spacing issues

    You seem to be putting each row of data all in one column. If you put the data in multiple columns then the problem is solved, otherwise it's just a listbox. Curious why the dots "." don't show up. Are you striping them out. Do you use code to load the rows?

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: List view spacing issues

    Not all fonts are created equal.

    In your top view, you are using a "fixed-width" font. In those kinds of fonts, every character is the same width. This is very useful for aligning text in columns. Some better-looking fixed-width fonts include Consolas and Courier, the one you're using looks like System and it's kind of harsh on the eyes.

    In the bottom view, you're using a "variable-width" font, probably the default "MS Sans Serif". In those kinds of fonts, each character might have a different width. These tend to be more pleasing to the eye and easier to read. But it means "MMMMM" is often at least twice as wide as "IIIII", and that makes it very, very hard to align text in columns using only tabs and spaces.

    So a quick fix would be to use a fixed-width font. A more involved fix would be to use a control that displays text in a tabular format, like ListView or DataGridView.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,244

    Re: List view spacing issues

    SS,

    I thought both were using fixed font but after looking a little harder, I think your right. I'm surprise that all those extremely long, maybe serial numbers, all are the same length. Or maybe it's just these old eyes.

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: List view spacing issues

    Sitten has already given the correct answer here, just as a comment, If you have something inside each text line that can be used as field separator then you should be able to arrange that data into columns inside the Listview, using column headers.. and that would look much better than just showing text lines like that.

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: List view spacing issues

    Oh, yeah, I didn't notice that you were using a ListView already, for some reason I thought your post said "ListBox". So wes4dbt and jcis's advice is particularly pertinent: if you could separate your text into columns yourself, you could utilize columns in the ListView to make everything line up.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  7. #7

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,346

    Re: List view spacing issues

    Quote Originally Posted by Sitten Spynne View Post
    Not all fonts are created equal.

    In your top view, you are using a "fixed-width" font. In those kinds of fonts, every character is the same width. This is very useful for aligning text in columns. Some better-looking fixed-width fonts include Consolas and Courier, the one you're using looks like System and it's kind of harsh on the eyes.

    In the bottom view, you're using a "variable-width" font, probably the default "MS Sans Serif". In those kinds of fonts, each character might have a different width. These tend to be more pleasing to the eye and easier to read. But it means "MMMMM" is often at least twice as wide as "IIIII", and that makes it very, very hard to align text in columns using only tabs and spaces.

    So a quick fix would be to use a fixed-width font. A more involved fix would be to use a control that displays text in a tabular format, like ListView or DataGridView.
    That was it...I left for the day yesterday before I posted it was solved. Here it is formatted with a "fixed" font.
    Attached Images Attached Images  
    Please remember next time...elections matter!

  8. #8

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,346

    Re: List view spacing issues

    Quote Originally Posted by Sitten Spynne View Post
    Oh, yeah, I didn't notice that you were using a ListView already, for some reason I thought your post said "ListBox". So wes4dbt and jcis's advice is particularly pertinent: if you could separate your text into columns yourself, you could utilize columns in the ListView to make everything line up.
    This is a quick and dirty program designed to allow one user to strip test cases off a large text files. The list view is just to show the data that will be written to an output text file.
    Please remember next time...elections matter!

  9. #9

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,346

    Re: List view spacing issues

    Quote Originally Posted by Sitten Spynne View Post
    Oh, yeah, I didn't notice that you were using a ListView already, for some reason I thought your post said "ListBox". So wes4dbt and jcis's advice is particularly pertinent: if you could separate your text into columns yourself, you could utilize columns in the ListView to make everything line up.
    For some reason the forum will not let me add to your reputation points. It says I need to spread some around first. I did one for the other two posters but I still can't give you a point. Sorry!
    Please remember next time...elections matter!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width