5 Replies - 7158 Views - Last Post: 16 March 2012 - 10:53 AM Rate Topic: -----

#1 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 07:58 AM

Hi,

I have been trying to pull rows from my access database into a list box, so the rows do appear on the list box, however the columns are not spaced out, and when I put & Space(10) & inside the ListBox1.Items.Add() the values are all scattered around. How do I fix this?

And how do I add column headers for them?

        TransactionTableApt.FilltList(LoyaltyDataSet.Transaction, busid1)

        Dim x As Integer = 0
        Do While x <= (LoyaltyDataSet.Transaction.Count - 1)

            Dim TransactionId As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("TransactionId"))
            Dim tValue As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("tValue"))
            Dim cPoints As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("CollectedPoints"))
            Dim aPoints As String = LoyaltyDataSet.Transaction.Rows(x)("PointsRedeemed").ToString
            Dim tDate As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("tDate"))
            Dim CardNo As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("CardNo"))
            
            ListBox1.Items.Add(TransactionId; tValue; cPoints; aPoints; tDate; CardNo)

            x = x + 1
        Loop



Is This A Good Question/Topic? 0
  • +

Replies To: ListBox, Adding column headers and spacing out columns

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 08:07 AM

First what control is the listbox1? I can't seem to get that 13th line to work here, so I'm not sure how you are. Second, since they are all strings why don't you just add spacing after each?

 ListBox1.Items.Add(TransactionId & " "; tValue & " "; cPoints & " "; aPoints & " "; tDate & " "; CardNo)



Also how about adjusting the column width property?

This post has been edited by trevster344: 16 March 2012 - 08:12 AM

Was This Post Helpful? 0
  • +
  • -

#3 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Re: ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 09:01 AM

View Posttrevster344, on 16 March 2012 - 08:07 AM, said:

First what control is the listbox1? I can't seem to get that 13th line to work here, so I'm not sure how you are. Second, since they are all strings why don't you just add spacing after each?

 ListBox1.Items.Add(TransactionId & " "; tValue & " "; cPoints & " "; aPoints & " "; tDate & " "; CardNo)



Also how about adjusting the column width property?


Apologies, that ";" wasnt supposed to be there, I was just testing to see if it worked.

well I did try the column width, and multi column = true, however it doesnt seem to want to work.

The issue with & " " & and spacing like this is the number of characters which are different for each row and as a result it messes everything.

any other ideas?
        Dim x As Integer = 0
        Do While x <= (LoyaltyDataSet.Transaction.Count - 1)

            Dim TransactionId As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("TransactionId"))
            Dim tValue As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("tValue"))
            Dim cPoints As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("CollectedPoints"))
            Dim aPoints As String = LoyaltyDataSet.Transaction.Rows(x)("PointsRedeemed").ToString
            Dim tDate As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("tDate"))
            Dim CardNo As String = CStr(LoyaltyDataSet.Transaction.Rows(x)("CardNo"))
            ListBox1.MultiColumn = True
            ListBox1.ColumnWidth = 20
            ListBox1.Items.Add(TransactionId & " " & tValue & " " & cPoints & " " & aPoints & " " & tDate & " " & CardNo)

            x = x + 1
        Loop


This post has been edited by vbprotobe: 16 March 2012 - 09:02 AM

Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 09:10 AM

Yes I would suggest using a datagridview. It's designed for this sort of thing. I'll post some code here soon. :)
Was This Post Helpful? 0
  • +
  • -

#5 vbprotobe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-March 12

Re: ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 09:23 AM

View Posttrevster344, on 16 March 2012 - 09:10 AM, said:

Yes I would suggest using a datagridview. It's designed for this sort of thing. I'll post some code here soon. :)


many thanks mate, well I am ok working with Data Grid view, it should be fine, I was wondering whether there is a way round this.

Many thanks for your help anyways
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,927
  • Joined: 25-September 09

Re: ListBox, Adding column headers and spacing out columns

Posted 16 March 2012 - 10:53 AM

You could set your ListBoxes font to a FixedWidth type and the spaces would be uniform but you could just use the listview and add columns to it. Like the datagrid, the listview columns are sizeable and clickable so you can set up sorts to rearrange your data. The datagrid is fine too but if you're looking for more of a listbox look with columns, the listview is a closer resemblance.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1