Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"tab" feature used for spacing text 1

Status
Not open for further replies.

lunaclover

Programmer
Joined
Jun 22, 2005
Messages
54
Hi -
I know in VB6 there was something you could do in order to line text up if it were in a textbox, listbox, etc. So if you had two columns of data you could say something like:

listbox.items.add("Summer ", <tabfeature> , "a season")
listbox.items.add("Fall" , <tabfeature>, "a season")

so that the "a season" would line up together. I know that is a bad example but hopefully you get the idea.

I have been trying to count spacebar hits and that obviously doesn't work in lining anything up. Does anybody know about this feature and if I can use it in VB.net?

Thanks!
Luna
 
MyString.PadLeft or MyString.PadRight
 
I suppose using a fixed width font is out of the question?

I think the only other way would be to override the drawing methods for the items and do it yourself.

Sorry I couldn't be of more help.
 
I was under the impression they were using a fixed width, now I am thinking otherwize as well. One thing you can do is OwnerDraw the listbox, and split your string by a tab character, and draw them at certain x-positions for each column.
 
I don't think there is any other way although there are probably some 3rd party controls that would have a columns property. Or ...

What about using a ListView in Detail view?

Hope this helps.
 
Now that you mention it, I think I did. It may have been for a combobox, however, you can do basically the same thing with a list box too.
 
well, this might show my vb ignorance, but I got caught up on this column thing again for my listbox. I have noticed that there is a property called 'multicolumn' that you can set to true, and then the help file has an example of code you can use to set the length of your column. Really, to my defense, I just bought a book and started programing. See, I can't even spell it right.
Now - what is this code doing? Is this where I'm supposed to put my columns? In what format?
Code:
Dim x As Integer
        ' Add items to the ListBox.
        For x = 0 To 50
            lstHeater.Items.Add("Items " + x.ToString())
        Next x
I know what it's doing except for the .ToString() part - what is this?

Thank you -
Luna
 
Luna, the columns referred to here are, I think forr wrapping purposes - to allow you to get twice as much data for example in the same height. That's why I suggested using a ListView.


Hope this helps.
 
What does using a listview in detail view mean? Sorry, I don't get it.
 
The .ToString is converting the numeric x to its string representation to display in the listbox.
 
Think of Windows Explorer. On the left you have a Tree View, on the right you have a ListView. If you go to the View menu, you have options for for display formatting of the ListView. If you select Detail you have multiple columns showing the filename, size, type etc.

Hope this helps.
 
Drop a ListView on a Form and set a couple of properties:

View -> Details
HeaderStyle -> None

Then try this ...

Code:
 Private Sub LVAddItem(ByVal item As String, ByVal subitem As String)

    Dim itm As New ListViewItem(item)
    itm.SubItems.Add(subitem)
    ListView1.Items.Add(itm)
    itm = Nothing

  End Sub

  Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

    LVAddItem("Summer", "Season")
    LVAddItem("Winter", "Season")
    LVAddItem("March", "Month")

  End Sub

Hope this helps.
 
Sorry, I forgot to add in the properties section

Add as many Columns as you need, set the Width and TextAlignment as required for each Column - you can ignore the other properties, the Name doesn't matter and the Text wont show because we've said don't show headers.


Hope this helps.
 
Thanks earthandfire. I guess I need to take some classes. You have been more than helpful.

Here is the output -
ListViewItem: {Summer}
ListViewItem: {Winter}
ListViewItem: {March}

Also - I don't know how to set as many columns as I need, and view and headerstyle are not properties listed as far as I can see.

Thanks anyway, it's not you it's me, and I'm giving up now just because I really can't bear to ask for your help anymore on details that are apparently supposed to be obvious.

Luna
 
Just give us lots of stars and we are bound to help you for the rest of your or our days (wichever ends first).

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Luna, ignore chrissie - and don't give up. If you could cope with the two forms talking to each other from a week or so ago, then I promise you this is easy.



Make sure you are using a ListView control not a ListBox.

Select the ListView and in the property grid click on the AZ button (on the grid's toolbar), this will make sure the properties are all listed in alphabetical order. As you scroll through the list you should see:

..
..
Columns -> (Collection)
..
..
HeaderStyle -> Clickable
..
..
View -> LargeIcon
..
..

These are the default settings.

Changing HeaderStyle and View are straightforward.

Select HeaderStyle and then select None from the drop down list (arrow on right of property)

Select View and then select Details from the drop down list (arrow on right of property)

Setting up the columns is a little harder, but still quite straightforward.

Select Columns and click on the elipsis (...) button to the right.
A dialog box appears with two columns and a number of buttons.

Click Add and the left column shows:
[0]ColumnHeader1
the right column is like a property grid - for now just ignore this grid.

We need two columns so click Add again
now on the left you've got:
[0]ColumnHeader1
[1]ColumnHeader2

Now click OK


Make sure your ListView is called ListView1 and make sure that you have a Button called Button6.

Copy and paste my code from the earlier example and test it.

Let me know how you get on.
 
Hey, what did I do. I was trying to be friendly and tell him/her to keep trying and never give up. Probably it was interpreted all wrong, so once again sorry for that.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Your forgiven, chrissie. But try, I know it was a long time ago (if ever), to remember what it was like when you first started programming and hit a brick wall, especially over something that really should have been simple. [wink]
 
I do, I promise, I still hit brick walls mostly when slightly intoxicated.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top