Output to a listbox 
Author Message
 Output to a listbox

Hello,

Newbie question.

I'm trying output some data into a listbox but it doesn't quite look
like what I want.  For example I'm outputting a string (name) that was
read
in from a file, followed by two byte type (age, score) variables.  My
output looks
like this:

John Doe  3095
Fred Flintstone  4575
Bart Simpson  1286

I'm using the following code to produce the output:
    List1.AddItem person.name & person.age & person.score

I would like to have the data displayed in columns.  I defined the field
"name" to be 20 chars
in length and thought that the shorter names would be padded with spaces
but it doesn't appear
to be doing that.  Is there a better way to do this or possibly another
control I should be using?

I'd really like to add column headings and have a more "professional"
looking display.  The ListView
control looks cool but I think it might be overkill for what I want to
do (not to mention more complex).

Thanks



Tue, 14 Sep 2004 02:38:17 GMT  
 Output to a listbox

Quote:

> I'm trying output some data into a listbox but it doesn't quite look
> like what I want.  For example I'm outputting a string (name) that was
> read
> in from a file, followed by two byte type (age, score) variables.  My
> output looks
> like this:

> John Doe  3095
> Fred Flintstone  4575
> Bart Simpson  1286

> I'm using the following code to produce the output:
>     List1.AddItem person.name & person.age & person.score

Use the LB_SETTABSTOPS, Luke...

 URL:http://groups.google.com/groups?selm=an_465296294

 URL:http://groups.google.com/groups?selm=33d35288.6399963%40news.mayn.de

--
Joe Foster <mailto:jlfoster%40znet.com>     Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Tue, 14 Sep 2004 02:59:58 GMT  
 Output to a listbox
OK .. for columns grab this .....
http://www.mvps.org/vbnet/code/listapi/cooltabs.htm and read this .....
http://www.mvps.org/vbnet/code/listapi/listboxtabs.htm

The listview isn't bad at all .. (not like the treeview - a horrid interface
to program).

With a listview, you declare a variable of type ListItem. You then set that
variable = the newly added item (aka the first column of data). You then use
the subitem() property of the variable to assign the values to the remaining
columns. IE ..

Private Sub Form_Load()

  'create the columns ...
   With ListView1
      .ColumnHeaders.Add , , "Name"
      .ColumnHeaders.Add , , "Age"
      .ColumnHeaders.Add , , "Score"
      .View = lvwReport
   End With

End Sub

Private Sub Command1_Click()

  'add the items
   Dim itmx As ListItem

   Set itmx = ListView1.ListItems.Add(, , "John Doe")
   itmx.SubItems(1) = 30
   itmx.SubItems(2) = 95

   Set itmx = ListView1.ListItems.Add(, , "Fred Flintstone")
   itmx.SubItems(1) = 45
   itmx.SubItems(2) = 75

   Set itmx = ListView1.ListItems.Add(, , "Bart Simpson")
   itmx.SubItems(1) = 12
   itmx.SubItems(2) = 86

End Sub

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As
MSComctlLib.ColumnHeader)

  'sort by column clicked
   Static bOrder As Boolean
   bOrder = Not bOrder

   ListView1.SortKey = ColumnHeader.Index - 1
   ListView1.SortOrder = Abs(bOrder)
   ListView1.Sorted = True

End Sub
--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


Quote:
> Hello,

> Newbie question.

> I'm trying output some data into a listbox but it doesn't quite look
> like what I want.  For example I'm outputting a string (name) that was
> read
> in from a file, followed by two byte type (age, score) variables.  My
> output looks
> like this:

> John Doe  3095
> Fred Flintstone  4575
> Bart Simpson  1286

> I'm using the following code to produce the output:
>     List1.AddItem person.name & person.age & person.score

> I would like to have the data displayed in columns.  I defined the field
> "name" to be 20 chars
> in length and thought that the shorter names would be padded with spaces
> but it doesn't appear
> to be doing that.  Is there a better way to do this or possibly another
> control I should be using?

> I'd really like to add column headings and have a more "professional"
> looking display.  The ListView
> control looks cool but I think it might be overkill for what I want to
> do (not to mention more complex).

> Thanks



Tue, 14 Sep 2004 11:11:56 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie: Passing an argument to a query, and specifying output to a ListBox

2. A ListBox: Input and Output

3. please help , i need to output the contents of a listbox to a text fil , TIA

4. Binary chars in output using Open xxxx For Output As #1

5. Output VBScript to two different output windows

6. How to write output to the Output/Debug window in Visual Studio

7. Move ListBox items to another ListBox

8. Store Text in Listbox.Editing, and storing in Listbox

9. VB3: Setting listbox based on value of other listbox

10. Write contents of listbox to text file/populate listbox from text file

11. How to scroll a listbox and scroll another listbox along

12. HELP: ListBox scrolling Q (listbox)

 

 
Powered by phpBB® Forum Software