Solved

list box find

Posted on 2004-08-17
7
264 Views
Last Modified: 2010-04-17
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
Comment
Question by:DARKSAGES
7 Comments
 
LVL 6

Assisted Solution

by:pillbug22
pillbug22 earned 100 total points
ID: 11823673
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11823941
DARKSAGES,

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

Idle_Mind
0
 

Author Comment

by:DARKSAGES
ID: 11824268
vb
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 2

Assisted Solution

by:kouroshparsa
kouroshparsa earned 100 total points
ID: 11825026
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
 
LVL 7

Assisted Solution

by:jacobhoover
jacobhoover earned 100 total points
ID: 11825411
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
 
LVL 3

Accepted Solution

by:
Stimphy earned 100 total points
ID: 11827401
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
 
LVL 23

Assisted Solution

by:gecko_au2003
gecko_au2003 earned 100 total points
ID: 11860370
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question