Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET Homework
Hi, I have a program in which teachers enter in students names and corresponding marks. I have completed the entering of data into a listview in a separate form, however I am having trouble creating a search form which searches through the students names entered, and displays in a message box whether the students name is found with their mark that has been entered, or "Name not found". The search is completed by entering the search item into a textbox, and then clicking a button called search, where in the listview, 0 is the item of the students name and subitem(1) is the students mark.
 
So far I have the following code:
Dim SearchItem As ListViewItem = frmStudentRecords.ListView1.FindItemWithText(txtSearchItem.Text, False, 0, True)
 
        If SearchItem IsNot Nothing Then
            Me.Hide()
            frmStudentDatabase.Show()
 SearchItem.Selected = True
            MsgBox(txtSearchItem.Text & " was found, with a mark of " & frmStudentDatabase.ListView1.Items(txtSearchItem.Text).SubItems(1).Text)
        Else
            MsgBox(txtSearchItem.Text & " was not found in the Student Database")
        End If
I think the line of code :
MsgBox(txtSearchItem.Text & " was found, with a mark of " & frmStudentDatabase.ListView1.Items(txtSearchItem.Text).SubItems(1).Text)
is wrong, however I am not sure how to display the subitem of the item properly.
Posted 25-Dec-12 17:25pm
b2906301
Edited 25-Dec-12 19:46pm
v6
Comments
Orcun Iyigun at 26-Dec-12 1:47am
   
Have you debugged it yet and see what values you are getting?
AnnuBhai at 28-Feb-13 2:33am
   
good searching code thanx

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can start thinking of the problem you've mentioned in the following line:
MsgBox(txtSearchItem.Text & " was found, with a mark of " & frmStudentDatabase.ListView1.Items(txtSearchItem.Text).SubItems(1).Text)
 
if your code passes successfully the condition to get to execute the line for showing a message including the student mark then it means you don't have to ask the ListView1 to find the same item again, right?
P.S. when you ask ListView1.Items() to find an item for you you should either use an Integer (Indicating the index of the item you're looking for) or a String (Indicating the key [Name] of the item you're looking for) so both of them have nothing to do with the item's text and so if the items key or name is not set then ListView1.Items(String) won't give result.
now you can modify the conditional block statements above to be like this:
Me.Hide()
frmStudentDatabase.Show()
' I just replaced frmStudentDatabase.ListView1.Items(txtSearchItem.Text).SubItems(1) with SearchItem.SubItems(1).Text
' and inserted a focus call function to get ListView1 focused |after| showing the message
' focused so when SearchItem is selected, is apparently selected too.
MsgBox(txtSearchItem.Text & " was found, with a mark of " & SearchItem.SubItems(1).Text)
frmStudentDatabase.ListView1.Focus()
SearchItem.Selected = True
 
Test it and get back to us, if nothing seems to happen then please add a msgbox call function before hiding the current form, in code:
 
Add something like -> MsgBox("Found An Item!")
Before this line -> Me.Hide()
 
Good luck
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 324
1 Sergey Alexandrovich Kryukov 182
2 Maciej Los 159
3 Hard_Rockz 143
4 Richard MacCutchan 125
0 OriginalGriff 5,374
1 Sergey Alexandrovich Kryukov 4,713
2 Peter Leow 2,944
3 DamithSL 2,465
4 Maciej Los 2,270


Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid