Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Add Items In Multiple Columns Of A Listbox


Does anyone know how to add items into 2 columns of a listbox?
I have 2 columns but when I do this:
lstTopic.AddItem rs.Fields(0)
the value is added into the first column. How do i add an other value in the second column?
Thanks!!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
I Want To Display Data In Two Columns In Listbox And Add Items In Listbox How Is It Possible In Vb 6.0
i want to display data in two columns in listbox and add items in listbox how is it possible in vb 6.0 ...?

I Want To Display Data In Two Columns In Listbox And Add Items In Listbox How Is It Possible
i want to display data in two columns in listbox and add items in listbox how is it possible ...?

Add Items To A Listview Multiple Columns
Hi... I have a listview with 3 columns... how can i add items to the second and the third column? i know it's a stupid question but i can't solve it


Thanks in advance

simons

Add Items To A Listbox With 3 Columns
HI, everyone!

How can i add items to listbox columns?
Letīs say for example i want to add items to the column 3 of the listbox, how can i do this?

thanks.

Adding Items To Multiple Columns In Lisview
Could someone give me some quick same code of how to add items to multiple columns in Listview?

Say column 1 is the filename, and column 2 is the filesize.

would it be something like this

Listview.listitems., ,.........

Thanks

Adding Items To ListBox Whith 2 Columns
How can I add items to a Listbox whith some columns , from a recordset ? in a Listbox whith one column, I used Additem , but I like to feel 2 columns, each one is a field from a recordset.
Thanks,
Richard.

I Want To Make Two Columns For Adding Items In Listbox In Visualbasic6.0
i want to make two columns for adding items in listbox in visualbasic6.0 ...?

Listbox Multiple Columns
I am using a listbox and I want to have columns to devide the information. I was wondering if this is possible? I should also mention I am using VBA within Excel.

Multiple Columns In Listbox
I have a listbox (VB6) with 3 columns. However, I cannot figure out how to fill in columns 2 and 3. List1.additem only takes a single string, and if i use additem again, it starts on the next line, leaving column 2 and 3 empty. How do I fill the other columns?

Listbox - Multiple Columns?
Is it possible to create multiple columns in a listbox?
I read somewhere that listview can handle it but I don't know how to do.

Multiple Columns In VB Listbox?
Is there a way to put data in multiple columns in VB without having all these fussy vbtabs that I've seen in various solutions online?

On a listbox I'd like to put a list of teams and next to them the number of cases in the system pertaining to them.

I have multiple listboxes on the form that I have to populate so I wrote this code to do it...I was hoping whatever solution I find with multiple columns will fit what I already have (if it stinks please tell me, I'm always looking to improve):


Code:
Call ListBoxLoop(intLower, intUpper, rstArray(), strSQLArray(), ctlListArray())



Code:
Public Function ListBoxLoop(intLower, intUpper As Integer, rstArray() As ADODB.Recordset, _
strSQLArray() As String, ctlListArray() As ListBox)
Dim i As Integer
For i = intLower To intUpper
Set rstArray(i) = New ADODB.Recordset
rstArray(i).Open strSQLArray(i), cnConn, adOpenForwardOnly
ctlListArray(i).Visible = False
Do While Not rstArray(i).EOF
ctlListArray(i).AddItem (rstArray(i).Fields(0))
rstArray(i).MoveNext
Loop
ctlListArray(i).Visible = True
Next i
End Function

Multiple Columns In A Listbox
I need to have multiple columns in a listbox and don't know how.

Multiple Columns In A Listbox
In a listbox that has been set to have multiple columns, is there a way to push added items into specific columns?

If not is there another control that would be better suited to this?

Thanks,
John

ListBox With Multiple Columns
Has anyone here used multiple columns with a listbox? I haven't, I'm not quite sure how it works.

ListBox Control - Multiple Columns
Hello,

I am unable to fill the column headings on my ListBox control.

When I set ListIndex to 0, it appeared to refer to the next row after the Headings, not the Row of Headings.

How do you set the Headings?

I have 15 columns. The ListBox is on a Form.

CJ

Multiple Listbox Items
I have a standard listbox that instead of only one item per line I have 3 items per line such as: Quantity, ItemNum, Price. I want to add these items to their matching columns in my database of quantity, ItemNum, and Price.

Is there a column property of the listbox that I can use to extract the Items individually?


rs is my recordset

Do while rs.Eof = False
list1.addnew = rs!Quantity
Loop

This only gets one item per line.

Remove Multiple Items From A Listbox
How can I remove multiple items from a listbox?

I have tried this, but it won't work....


Code:
Dim i As Integer

For i = 0 To Me.lstFiles.ListCount - 1
If Me.lstFiles.Selected(i) = True Then
Me.lstFiles.RemoveItem Me.lstFiles.List(i)
End If
Next i

Remove Multiple Items From Listbox
Hi,

I have a listbox which is multiple selection enabled and I have a button which removes all selected items by looping through like so:


Code:
Do While PlayList.SelectedIndex <> -1
PlayList.Items.RemoveAt(PlayList.SelectedIndex)
Loop
This works, the problem is I have another piece of code which is triggered by the selected index being changed. It checks the count of the listbox and if empty does one thing and if not does another.

The problem is the selected index changes before the item is removed which means that even when the list is empty the count shows one and the program takes the wrong path.

Can anyone help?

Thanks
Stephen Reid

Listbox And Remove Multiple Items
i have this code for loading and removing items from a list box. i am generating an error with my remove item statment. i want to add the item at position i to the correct list box and also delete the item at postion i from both boxes. how i generate an invalid procedure call a the first removeitem command in either statement.

dim x as interger
x = 4

If card1Value > card2Value Then
MsgBox "card1 bigger " & card1 & " " & card2
For I = 0 To X
MsgBox I
lstDeck1.AddItem lstDeck1.List(I)
lstDeck1.RemoveItem lstDeck1.List(I)
lstDeck1.AddItem lstDeck2.List(I)
lstDeck2.RemoveItem lstDeck2.List(I)

Next
Else
MsgBox "card2 bigger" & card1 & " " & card2
For I = 0 To X
MsgBox I
lstDeck2.AddItem lstDeck1.List(I)
lstDeck1.RemoveItem lstDeck1.List(I)
lstDeck2.AddItem lstDeck2.List(I)
lstDeck2.RemoveItem lstDeck2.List(I)
Next I


any thoughts?

Adding Multiple Items Into A Listbox At Once
I am trying to access records from a database that is being created as the user enters data into the program. When they load the next form after entering the information, the data they entered is supposed to come up in a picturebox, with a few added items. The requirements of the assignment are that it has to print to a picturebox, but I can't get more than one record to print at a time. This is a program where names of students and their grades are entered, then on the next form, it is supposed to display all of their grades, both numeric and letter in a picturebox. I am successful in getting one piece of data to print to a picturebox, and I can also get it to print to a listbox or textbox, but never more than one piece of data. Is there anything I can do to get it to print out all the records from 2 columns of my database? I am trying to send the data to a listbox, then I am sending that to a textbox, then I am finally printing what's in the textbox.

Here is my code.

Private Sub Form_Load()
Dim i As Long
Dim str As String
index = 0

Set dbCon = New ADODB.Connection 'sets connection
dbCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=grades.mdb"
dbCon.Mode = adModeReadWrite
dbCon.CursorLocation = adUseClient
dbCon.Open

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

addGrade = "SELECT numbers FROM Store ORDER BY Numbers DESC"
rs.Open addGrade, dbCon, _
adOpenForwardOnly, adLockReadOnly, _
adCmdText


With rs
Do While Not .EOF
list1.listitems.add(index + 1, , !numbers)
str = !numbers
Text1 = str & Text1
.MoveNext
Loop
.Close
End With


' List1.AddItem rs("numbers")
' Text1 = rs("numbers")
' rs.MoveNext

' picGrades.Print rs("numbers") 'prints text to picturebox
'rs.Close


'Centers the form
frmStudents.Top = (Screen.Height - frmResults.Height) / 2
frmStudents.Left = (Screen.Width - frmResults.Width) / 2
End Sub

I am getting a syntax error with this line of code:
list1.listitems.add(index + 1, , !numbers)
I used that because someone else on this forum gave me the code, but I do not know enough about VB to know what is wrong with the code.

Thanks for any help!

Multiple Forms, Listbox Items
I have 2 forms.

When I add something to the listbox in the 2nd form and press the close button and reload it from a button on the 1st form, the items in the listbox are gone.

Is there a way to make the items stay?

Select Multiple Items In ListBox!
A VB6 Form has 2 ListBoxes which are populated from 2 different text files. Some of the items in the 2 ListBoxes are the same i.e. such items exist in both the ListBoxes. Note that the MultiSelect property of both the ListBoxes are set to 2 - Extended. The 2 ListBoxes are named List1 & List2.

When an item is selected in List1, I want that item, if it exists in List2, to get selected automatically in List2. This is how I have done it (Thanks to Hack for his input):
VB Code:
Private Sub List1_Click()    Dim strItem As String    Dim i As Long    Dim j As Long     strItem = List1.List(List1.ListIndex)     For i = 0 To List2.ListCount - 1        If List2.List(i) = strItem Then            List2.Selected(i) = True            Exit For        Else            For j = 0 To List2.ListCount - 1                List2.Selected(j) = False            Next        End If    NextEnd Sub
The problem is when more than 1 item is selected in List1. When I select Item1 in List1 & assuming that Item1 exists in List2 as well, then Item1 gets selected in List2 - till this point, no problem but keeping Item1 selected in List1, when I next select Item2 in List1 & assuming that Item2 exists in List2, then Item2 does get selected in List2 but Item1 in List2 gets de-selected whereas I want that since both Item1 & Item2 are selected in List1, both these items should automatically get selected in List2 as well. If either Item1 or Item2 (or both) are de-selected in List1, then these 2 items in List2 should also get de-selected accordingly.

In other words, what I want is when items are selected/de-selected in List1, if those items exist in List2, then those items should automatically get selected/de-selected accordingly.

What changes are needed in the above code to implement this?

Selecting Multiple Items In A Listbox
Hey everybody!

I've got a listbox question:

Is it possible, to do this..

I've set a listbox to 'multiselect - 2. extended', which lets me highlight multiple entries.

I want to be able to click a button and then list all of the selected entries through msgboxes..

So, if I had this:

number 1 - selected
number 2
number 3 - selected
number 4
number 5 - selected

and I hit the button, I would get three message boxes pop up, with "number 1", "number 2", and finally, "number 3" in them

Thanks to anybody that answers this

Selecting Multiple Items In Listbox
Hi All,

I have a list box which is populated from an array in the following manner


VB Code:
For lintCtr = 0 To UBound(ClinicArray, 2)  '1 for Clinic name  ClinicList.AddItem ClinicArray(1, lintCtr)  '0 for Clinic id  ClinicList.ItemData(lintCtr) = CInt(ClinicArray(0, lintCtr))Next


Now what I need to do is when I load my new form that it checks in the database for which clinics someone belongs to and then automatically selects them.

For example one person is connected to 2 clinics, clinicid 2 and clinicid 9

These integers match the integers populated in the ItemData options.

How would I go about using the ClinicList.Selected(???) = TRUE?

I have the following but it fails if the clinicid is greater than 9??


VB Code:
Do While Not RS.EOF     ClinicList.Selected(ClinicList.ItemData(RS("cu_ClinicID"))) = True     RS.MoveNextLoop

Retreiving Multiple ListBox Items
Any suggestions on how to check for multiple selected items in a ListBox and pass each value to a MAPI control.

I have no problem picking one item and this being passed correctly, but I'm having problems with multiple selection of items. I have been fighting with a For-Next loop trying to test each value as selected or not. Any sample code would be much appreciated.

Sincerely,

Adding Multiple Items To Listbox?
Hi all! Yea, it´s me again =)
This time i want to populate a listbox with multiple items at once. I have a textbox in which i can add text and then
klick an "add" button to add the text to the listbox. But i´d like to be able to add (paste) several lines in the textbox
and have them all added to the listbox in one klick. It doesn´t seem possible to add more than one line at a time in
a textbox, is there another class which allows this, or how would i go about doing this?

Cheers!
Maverick

Combining Multiple Items From A Listbox...
Hi, I want to combine multiple items from a listbox and put them in a txt file. I know how to do the text file export thing. But I was needing help with the listbox.


I have 114 items in the listbox "H" "He" "Li" etc... I want to take those and add them to together, like He and Li because "HeLi" but also so H and He and Li become HHeLi. I want to add up to 15 of those altogether

ex. (
Items:
"A"
"B"
"C"
"D"
"E"
"F"
"G"
"H"
"I"
"J"
"K"

OUTPUT:
A
AB
ABC
ABCD
ABCDE
ABCDEF...
B
BA
BAC
BACD
BACDE
BACDEF...

but using the items from the list.

Selecting Multiple Items In A Listbox From Code.
How do you do this?

Just after I posted it I figured it out. Was forgetting to put = True at the end.

lstdeductions.Selected(deductions(i) - 1) = True

Lol....oh well.

Edited

Insert Multiple Items From Listbox To Database
hi i have a listbox where the style is checkbox, now i want to save the items that the user checked in the listbox to my database.. i am using MSSQL Server 2000 and here is my code.. i need help badly

For i = 1 To phaselist.ListCount - 1
If (phaselist.Selected(i) = True) Then
stmt2 = "Insert into savedphase (phaseID, projectID,
phaseName) VALUES ('"
stmt2 = stmt2 & phaselist.ItemData(i) & "', '"
stmt2 = stmt2 & Label4.Caption & "', '"
stmt2 = stmt2 & phaselist.Text & "');"

insertRecord (stmt2)
MsgBox "Success", vbOKOnly, "Good"

Exit Sub

End If
Next i


this code is located in the save button that i have created please help anyone..

Multiple Items Selected In Listbox Code
I know I've done this before, but I cannot remember the property or method I used to retrieve the selected items from a listbox. Suggestions?

How To Delete Multiple Selection Items From A Listbox?
On a form, I have two listbox's. One has items in it, the other is empty. I want to be able to transfer items from one listbox to the other. That part I can do. My problem, is that I want to delete the item, that is being transferd, from it's original listbox. For a single selection, it poses no problem, but if you have a multiple selection enable, it is more complex. I cant use the index after I use the removeitem once, since all the indexes are changed. Example: I have five items (index 0 through 4). I select item 1 & 3. Once I transfer these items to the other listbox, I now want to delete them. If I use the removeitem method once for the item index 1, the other item previously selected (index 3) now becomes index 2! So how can I keep track of all this as I delete items? Is using a while(there are still selected items) conditional loop part of the solution?

Multiselect Listbox And Selecting Multiple Items
Hi.

Well I have a multiselect listbox in Access 2000. I have populated the control and now wish to display the selected items for an existing customer (i.e. loading an existing customer and have their item selections displayed as an initial condition). Any ideas of how to do it? Thanks!

- Mike

Remove Multiple Listbox Items And Change Original
Ok, I have 2 list boxes in my form and by double clicking on one, it will add it to the other side, but what I want it to do is when it is double clicked, it will check if there is an item by the same name in the other, and if there is, not add a new item, but change the existing one by adding a number in front of it. Say I have a list box with the following items: Apple, Bannanna, Coke, Sprite, and Pepsi. When one of those is double clicked, it will check to see if there is already an item by that name in the second listbox, and if there is, change the first part or it to 2 Bannana or 3 Bannana if there is already 2. I have a feeling the way to go would be to use the mid function to check the beginning for the number and change that, but I dont know how to do that. I have found plenty of ways to check to see if there is an item by the same name, but I havnt found one that will change the original if there is. Any help would be appreciated.

How To Send Multiple Selected Items To Clipboard, From A Listbox
Good morning !


I understand how to select one item to the clipboard, but if I want to send multiple items to the clipboard AT THE SAME TIME, I don't understand how to do this.

I'm using a listbox control and need to process the selection of multiple items.

Calling Clipboard.SetText() for each item that is selected in the listbox, will replace the previously selected item that is in the clipboard.

thanks

Algorithm Critique: Removing Multiple Items From A Listbox
The issue is this: When you have a listbox that has its multi-select property set to something other than "None" (i.e., "Simple" or "Extended"), and you allow the user to remove items from the listbox, what is the best way to code the "remove" logic?

I have been using my own solution to this issue for quite some time, but I would like some feedback from other programmers. Please tell me either:
(1) Yes, Bruce, this is a fine way of doing this!
-or-
(2) What are you, crazy? There's a much better way to do this! (And of course tell me what it is.)

The code samples below refer to what would be behind the "Remove" command button that the user would click after making their selections from the list.

First of all, we can all appreciate that the following is the WRONG way to remove multiple items from a list box:


Code:
'Wrong logic

Dim X As Integer

For X = 0 To List1.ListCount - 1
If List1.Selected(intListX) Then
List1.RemoveItem X
End If
Next


The reason that the above code is wrong is that as you remove items from the list, VB automatically adjusts the ListCount property. So as you go through the above loop and remove items, the loop control variable (X in this case) becomes out of sync with the ListCount property, and you typically wind up with a value in the loop control variable that is not a valid array element for the list box, resulting in an "Invalid property value" run-time error.

The way I've been solving this problem is to change the For loop to use a Boolean variable that I set when I remove a selected item from the list, and then exit the For loop at that time. The For loop is nested within a Do loop that checks the Boolean variable to see whether or not an item was removed on that pass. As long as an item was removed, the Do loop continues. If no item was removed on a given pass, we know that there are no more selected items in the list to remove, so the Do loop can terminate.

This works, and seems reasonably fast. But is it unecessarily complicated? Is there a simpler way to do this that I have overlooked? This has just been a nagging question for me for a while.

Here's my code:

Code:

Dim X As Integer
Dim intStart As Integer
Dim intNewStart As Integer
Dim blnItemWasSelected As Boolean

intStart = 0
intNewStart = 0

Do
blnItemWasSelected = False
intStart = intNewStart
For X = intStart To List1.ListCount - 1
If List1.Selected(X) Then
intNewStart = X
List1.RemoveItem X
blnItemWasSelected = True
Exit For
End If
Next
Loop While blnItemWasSelected



Thanks in advance for your input.

[Edited by BruceG on 06-04-2000 at 04:37 PM]

Adding Multiple Items From Common Dialog Control To Listbox....... Help.....
I'm pretty sure this is posibble so can anyone help me please?

and also tell me how to find the hWnd of a window

Removing Multiple Identical Items, From A Sorted And An Unsorted Listbox...
Hi everyone...

I'm stomped on this one...

I have two listboxes on one of my forms. One is sorted and the other is unsorted.
Both contain the same items...Also the lisboxes are both set to multiselect...

I would like to remove the same items from both lists at the same time...So if
items 3, 5, and 7 were selected from the sorted listbox, how can I remove these
items plus the identical ones from the unsorted listbox?

Thanks in advance...

D-Race



Edited by - D-Race on 3/25/2005 8:10:50 PM

Autofilter With Multiple Columns And Multiple Criteria
Hi

I have a sheet of data, which I need to clear up. What I want to do is use the autofilter function to filter out the information that I need, leaving what I don't need visible and then delete the visible rows.

First filter is on column D, where I need to select all rows that are in "Unit1" and then filter on column C to select all rows that are NOT "Team1" or "Team2".

Code I have is:

vb/
Dim CheckRange As Range, DeleteRange As Range

Set CheckRange = Worksheets("Sheet1").Columns(7)
CheckRange.AutoFilter Field:=4, Criteria1:="Unit1"
CheckRange.AutoFilter Field:=3, Criteria1:="<>Team1", Operator:=xlOr, Criteria2:="<>Team2"

Set DeleteRange = CheckRange.SpecialCells(xlCellTypeVisible).EntireRow
DeleteRange.Delete
/vb

However this does not work. It filters out all the non "Unit1" rows fine, but then applied a filter to Column C that does nothing!

Can someone help put me out of my misery?

Adding Items In Columns In A Listview
Hello

I am using a listview control that l want to add items to. The Listview contains 2 columns. One for name and the other for price. The name and price will be input by using a text box. When the user presses the command button the 2 will be added to the listview box.

I am not sure how to add 2 items into the two columns.

My code so far.


Code:

'Create the listview headings
ListView1.ColumnHeaders.Add , , "Name of Fruit"
ListView1.ColumnHeaders.Add , , "Price of Fruit"
ListView1.View = lvwReport

'Code adding to the listview box, but not sure how to add price
Set objfruit = ListView1.ListItems.Add(, , name.Text)



Many thanks in advance

Steve

Copying The Items From My Listbox To Another Listbox Not In My Program?[UNSOLVED]
Hey!
As you can see I want to copy the items from a listbox in my form into another program(wich i didnt made it, but the program is made with VB)
How can I do this?
P.S : There are two listboxes in the other app!

Thank you!!

Combo Box With Multiple Columns
hi guyz...
i just wanna ask if its possible to have a
combo box with multiple column.
if its possible, how do i do this...

thnx.

Selecting Multiple Columns
i need to delete multiple cloumns from worksheet. Unfortunatly, i do not have any experience with VBA and excel. Can anyone point me to the information or tell me how to select multiple noncontigous columns at once.

I was going to do it this way but it occurred to me that the columns will get renumbered as they are deleted. So i figured there has to be some way to select multiple columns and then delete them all at once.

.Range(.Columns("B")).Select '.EntireColumn.Delete
.Columns("F").EntireColumn.Delete
.Columns("J").EntireColumn.Delete
.Columns("K").EntireColumn.Delete

Thanks,

Animaul

Multiple Columns List
In Access, you can make multiples-columns ComboBox.

For example, you can determine the ComboBox content by a sql query. Then, if this query return 3 fields, you can set the Columns property to 3 and the ComboBox display the 3 data for each row.

I want to do the same thing with Visual Basic: filling a ComboBox with data from an Access database.
But is it possible get more than 1 column in the ComboBox?

Datareports (Multiple Columns)
Is there a way to display information in multiple columns in a datareport? I know you can do it in Access but I haven't been able to find a way to do it with VB datareports. I want to display information for two records (instead of just one) on every row. (to save space).

Multiple Columns In Combo Box
How can I have more than one column in a combo box as we can have in Access forms.

Is it possible to do in VB with some API?

Combobox With Multiple Columns
Is it possible to create a combobox with 2 columns? If yes, how? I couldn't figure it out on my own and I couldn't find anything in the MSDN about it.

Thanks for the help,
Andy

Multiple Columns In A Combobox ?
Ok.. yesterday it was listboxes, and today..... well you get the picture. Can someone please drop a line explaining how I would add another column to a combobox?

Multiple Columns In A ComboBox
I would like to have 3 columns in my combobox.

this is the example of my actuel code made on ONE column where each fields are "concatanate" to form a strig that I had.


rst.Open "select ru_code_rue,ru_nom_rech,vi_code_vill from gestion_rue", cnn, adOpenKeyset, adLockOptimistic, adCmdText

rst.MoveFirst
Do While Not rst.EOF
chaine = rst!ru_code_rue & " " & rst!ru_nom_rech & " " & rst!vi_code_vill
If chaine <> "" Then
cbocoderue.AddItem chaine
End If
rst.MoveNext
Loop
rst.Close


But this code that make 3 distincts columns and it's not really nice.


But It's don't let me put the string "select ru_code_rue,ru_nom_rech,vi_code_vill from gestion_rue" in the property cbocoderue.rowsource.


I know that I have to work with the boundcoulmn, columncount and the columnwidth properties but I don't know exactly how.


thank for your help.


Dominic Lavoie

Multiple Columns In A Combo Box
Is there anyway to display multiple columns of data in a VB6 combo box?

Using the following doesn't work

     combobox1.additem "Some string" & vbtab & "Some other string"

It displays some odd characters in the string. Is it possible to do this, or has anyone come across any 3rd party components that do this?

Copyright Đ 2005-08 www.BigResource.com, All rights reserved