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

Adding daata in multicolumn Combobox

Status
Not open for further replies.

EVISSER

Programmer
Jun 3, 2003
32
AN
How Can I insert data in a combobox with multiple columns?

Regards
 
Evisser,

Noticing that vbTab doesn't work in comboboxes, i produced this code. It is commented and needs only a little tweaking for your program.

[tt]
Private Sub Form_Load()
'Declare Arrays for each column equal to the
'amount of rows you want.
Dim Col1Data(20) As String
Dim Col2Data(20) As String

'Declare Looping and Adding Variables
Dim AddLoop As Integer
Dim CurrentRow As String
Dim RowAmount As Integer

'Set Space Constant for Start of Column 2
Const C2Start = 40

'Set Column Data
Col1Data(1) = "Row 1 Col 1"
Col1Data(2) = "Row2 Col1"
Col2Data(1) = "Row 1 Col 2"
Col2Data(2) = "Row2 Col2"

'Check How Much of the array contains data
For AddLoop = 1 To UBound(Col1Data)
If Col1Data(AddLoop) <> &quot;&quot; And Col2Data(AddLoop) <> &quot;&quot; Then
RowAmount = AddLoop
End If
Next

'Start Loop using Total amount of used array data
For AddLoop = 1 To RowAmount
'Insert Correct Number of Spaces Into String
'Using Space Constant - No. of characters in Col 1
CurrentRow = Col1Data(AddLoop) & _
Space(C2Start - Len(Col1Data(AddLoop))) & Col2Data(AddLoop)

'Add Row to Combobox
Combo1.AddItem CurrentRow, AddLoop - 1
Next AddLoop



End Sub

[/tt]

Hope this helps.


jgjge3.gif
[tt]&quot;Very funny, Scotty... Now Beam down my clothes.&quot;[/tt]
 
Or Modify Part of the code as below to insert a line seperator before the Second Column.

[tt]
'Insert Correct Number of Spaces Into String
'Using Space Constant - No. of characters in Col 1
CurrentRow = Col1Data(AddLoop) & _
Space(C2Start - 3 - Len(Col1Data(AddLoop))) & &quot; | &quot; & Col2Data(AddLoop)
[/tt]

Hope this helps.

jgjge3.gif
[tt]&quot;Very funny, Scotty... Now Beam down my clothes.&quot;[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top