Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

list box find

I have a list box that contains data like this ip,username,computername. Now i need to be able to find an item just by the ip. I tried going record by record and comparing but this takes a while when you have to many entries. Any suggestions? Thanx
0
DARKSAGES
Asked:
DARKSAGES
5 Solutions
 
pillbug22Commented:
If you use an ArrayList to put the items in, then bind the ArrayList to the list box - the ArrayList has sorting and searching features
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
DARKSAGES,

What language are you working in?  VB6 or .Net?

Idle_Mind
0
 
DARKSAGESAuthor Commented:
vb
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kouroshparsaCommented:
First of all, "you have too many entries". How many approximately?
If you have less than 500 IP's I suggest:
1-Use another listBox for IP's
OR
2-When you add the data to the list box, if you are adding an IP, add it to the beginning of the list box. Then when you search for the IP, you reach the result faster.
OR
3- Depending on the amount and number of data (if more than 1000 IP's), you may want to sort the IP's in order to use the binary-search.
OR
4- A great idea is: when the user enters the data, as you add them to the listBox, also add the particular IP to a dinamic array. Then if you have less than 1000 IP's you can quickly go through the array...
It all depends on the program's structure. May be  you would describe your application a bit more.
0
 
jacobhooverCommented:
Several suggestions,

#1 and probably fastest if the IP can be the first item in the list and it is unique you can use.

Dim index as Long
index = SendMessage(hwnd of List Box, LB_FINDSTRING, -1, ByVal the IP address as a string)
listBox.ListIndex = index

#2 you could set the ItemData value to the IP address and scan it, however this would still be a loop

If you want more code or if I'm going where you want, just ask.
0
 
StimphyCommented:
Hello,
Why dont you use a listView?  It has searching options built into it without the need for API calls.

Just add a command button and a listView to the form and paste the following code.

Private Sub Command1_Click()
    Dim li As ListItem
    Set li = ListView1.FindItem("1690")
    li.Selected = True
    li.EnsureVisible
End Sub

Private Sub Form_Load()
    ListView1.View = lvwList
    ListView1.HideSelection = False
    Dim cnt As Integer
    For cnt = 1 To 5000
        ListView1.ListItems.Add , , cnt
    Next
End Sub

Regaurds,
Dave
0
 
gecko_au2003Commented:
This might be a stupid suggestion and considering I have only started using visual basic but couldnt you use an ADO control and make an access database to store all ip addys, usernames and computer names in to a database and then once you have retrieved them insert them into a database table then that way you can search through the database table to look for the relevant ip address and then from there bind that to the relvant record number and then you can ascertain there username, computer name, etc.??

I hope this helps, if not then like I said it was only a suggestion.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now