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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with adjustable columns in a ListBox 1

Status
Not open for further replies.

unclesvenno

Programmer
Sep 12, 2004
33
AU
Can anyone tell me if it's possible (and of course how to do it) to have adjustable column widths in a listbox. For example I am outputing a query to a listbox :

DoCmd.OpenForm "frmForm1"
Forms!frmForm1!lsbListBox1.RowSource = "Query1"

The resulting query has 4 columns which I would like to allow the user to adjust with their mouse.

Thanks again,
Uncle Svenno
 
uncleSvenno, here's a thought.
All I could think of, is have an option group, denoting which column to manipulate.
Dimension 4 Public variables(within the form) to hold & adjust, current column widths.
Then On MouseDown Event, Use Shift button to enlarge selected column, or Control to reduce....


Code:
Option Compare Database
Option Explicit
Dim sCountry, sCap, sCont, sTime As Single



Private Sub Form_Load()
Me.lstCountries.ColumnWidths = "1 in;1 in;1 in;1 in"
sCountry = 1: sCap = 1: sCont = 1: sTime = 1
End Sub

Private Sub lstCountries_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Shift = acShiftMask Then

    Select Case fraColumn
        Case 1: sCountry = sCountry + 0.1
        Case 2: sCap = sCap + 0.1
        Case 3: sCont = sCont + 0.1
        Case 4: sTime = sTime + 0.1
    End Select
    
        Me.lstCountries.ColumnWidths = sCountry & " in;" & sCap & " in;" & sCont & " in;" & sTime & " in"

ElseIf Shift = acCtrlMask Then

    Select Case fraColumn
        Case 1: sCountry = sCountry - 0.1
        Case 2: sCap = sCap - 0.1
        Case 3: sCont = sCont - 0.1
        Case 4: sTime = sTime - 0.1
    End Select
    
        Me.lstCountries.ColumnWidths = sCountry & " in;" & sCap & " in;" & sCont & " in;" & sTime & " in"

End If
 
Sorry, I hit the Submit button, a little prematurely.

fraColumn is the name of option group, lstCountries, ListBox (obviously), they will need to be changed, accordingly.

If Any further explanations required from me, or disparaging remarks from you,(LOL), I'll stay posted.

Hope this helps, good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top