Solved

list box find

Posted on 2004-08-17
7
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…

623 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