|
-
Jul 5th, 2012, 10:18 PM
#1
Thread Starter
Junior Member
[RESOLVED] Listview Search as type & show in Richtextbox error
Hi,
im encountering error in this code, Kindly help me
Code:
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
' Dim selArray As ListView.SelectedListViewItemCollection = ListView1.SelectedItems
' If selArray.Count > 0 Then
ListView1.Items.Clear()
Dim itm As ListViewItem
Dim i As Integer
For i = 0 To ListView1.Items.Count - 1
ListView1.Items.Item(i).BackColor = Color.White
ListView1.Items.Item(i).ForeColor = Color.Black
Next
With ListView1
itm = .FindItemWithText(txtSearch.Text, True, 0, True)
'tell me what im going to do in this line for searching that kind of method
rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm(0).Text))
If Not itm Is Nothing Then
.Items.Item(itm.Index).EnsureVisible()
.Items.Item(itm.Index).BackColor = Color.CornflowerBlue
.Items.Item(itm.Index).ForeColor = Color.White
.Items.Item(itm.Index).Selected = True
Else
MsgBox("No Record Found!")
For i = 0 To ListView1.Items.Count - 1
ListView1.Items.Item(i).BackColor = Color.White
ListView1.Items.Item(i).ForeColor = Color.Black
Next
.Items(0).EnsureVisible()
.Items.Item(0).BackColor = Color.CornflowerBlue
.Items.Item(0).ForeColor = Color.White
.Items.Item(0).Selected = True
txtSearch.SelectionStart = 0
txtSearch.SelectionLength = Len(txtSearch.Text)
txtSearch.Focus()
End If
' End if
End With
itm = Nothing
End Sub
Error Line.
Code:
rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm(0).Text))
-
Jul 5th, 2012, 11:05 PM
#2
Re: Listview Search as type & show in Richtextbox error
What is the error message? What are the values of the data you're using?
-
Jul 6th, 2012, 01:06 AM
#3
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
this is the error msg:-
Error 1 Class 'System.Windows.Forms.ListViewItem' cannot be indexed because it has no default property. C:\Users\KMV\Desktop\Code Library\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 61 80 WindowsApplication1
-
Jul 6th, 2012, 01:35 AM
#4
Re: Listview Search as type & show in Richtextbox error
itm(0).Text is wrong, the correct is itm.Text
Also, you should add
vb Code:
rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm(0).Text))
after
vb Code:
If Not itm Is Nothing Then
just in case .FindItemWithText(txtSearch.Text, True, 0, True) returns nothing
Try this new one
vb Code:
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged ' Dim selArray As ListView.SelectedListViewItemCollection = ListView1.SelectedItems ' If selArray.Count > 0 Then ListView1.Items.Clear() Dim itm As ListViewItem Dim i As Integer For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next With ListView1 itm = .FindItemWithText(txtSearch.Text, True, 0, True) 'tell me what im going to do in this line for searching that kind of method If itm IsNot Nothing Then rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm.Text)) .Items.Item(itm.Index).EnsureVisible() .Items.Item(itm.Index).BackColor = Color.CornflowerBlue .Items.Item(itm.Index).ForeColor = Color.White .Items.Item(itm.Index).Selected = True Else MsgBox("No Record Found!") For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next .Items(0).EnsureVisible() .Items.Item(0).BackColor = Color.CornflowerBlue .Items.Item(0).ForeColor = Color.White .Items.Item(0).Selected = True txtSearch.SelectionStart = 0 txtSearch.SelectionLength = Len(txtSearch.Text) txtSearch.Focus() End If ' End if End With itm = Nothing End Sub
-
Jul 6th, 2012, 01:41 AM
#5
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
Hi 4x2y
thanks in advance
its giving error as below and highlighting the code
InvalidArgument=Value of '0' is not valid for 'startIndex'.
Parameter name: startIndex
Code:
itm = .FindItemWithText(txtSearch.Text, True, 0, True)
if i use
Code:
Rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm.Text))
error as below
InvalidArgument=Value of '0' is not valid for 'startIndex'.
Parameter name: startIndex
-
Jul 6th, 2012, 01:48 AM
#6
Re: Listview Search as type & show in Richtextbox error
That's mean the listview is empty!
Why you clear it at the beginning ListView1.Items.Clear()
-
Jul 6th, 2012, 01:48 AM
#7
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
Ops sorry it is working
ListView1.Items.Clear() is the one giving error
its not refreshing the listview when i clear the textbox.
-
Jul 6th, 2012, 02:05 AM
#8
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
 Originally Posted by 4x2y
That's mean the listview is empty!
Why you clear it at the beginning ListView1.Items.Clear()
i did not notice that. sorry. how do we can refrsh the listview n empty the rtb1 if the textsearch is empty?
-
Jul 6th, 2012, 02:19 AM
#9
Re: Listview Search as type & show in Richtextbox error
Try this new one
vb Code:
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged If txtSearch.text = String.Empty Then rtb1.Text = String.Empty If ListView1.SelectedItems.Count > 0 Then ListView1.SelectedItems(0).Selected = False End If Else Dim itm As ListViewItem Dim i As Integer For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next With ListView1 itm = .FindItemWithText(txtSearch.Text, True, 0, True) 'tell me what im going to do in this line for searching that kind of method If itm IsNot Nothing Then rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm.Text)) .Items.Item(itm.Index).EnsureVisible() .Items.Item(itm.Index).BackColor = Color.CornflowerBlue .Items.Item(itm.Index).ForeColor = Color.White .Items.Item(itm.Index).Selected = True Else MsgBox("No Record Found!") For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next .Items(0).EnsureVisible() .Items.Item(0).BackColor = Color.CornflowerBlue .Items.Item(0).ForeColor = Color.White .Items.Item(0).Selected = True txtSearch.SelectionStart = 0 txtSearch.SelectionLength = Len(txtSearch.Text) txtSearch.Focus() End If ' End if End With itm = Nothing End If End Sub
-
Jul 6th, 2012, 02:31 AM
#10
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
No luck
its clearing the Rtb1
not refreshing listview
listview item still highlited
-
Jul 6th, 2012, 02:42 AM
#11
Re: Listview Search as type & show in Richtextbox error
Hope the following works
vb Code:
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged Dim itm As ListViewItem Dim i As Integer If txtSearch.Text = String.Empty Then For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next Else With ListView1 itm = .FindItemWithText(txtSearch.Text, True, 0, True) If itm IsNot Nothing Then rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm.Text)) .Items.Item(itm.Index).EnsureVisible() .Items.Item(itm.Index).BackColor = Color.CornflowerBlue .Items.Item(itm.Index).ForeColor = Color.White .Items.Item(itm.Index).Selected = True Else MsgBox("No Record Found!") For i = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next .Items(0).EnsureVisible() .Items.Item(0).BackColor = Color.CornflowerBlue .Items.Item(0).ForeColor = Color.White .Items.Item(0).Selected = True txtSearch.SelectionStart = 0 txtSearch.SelectionLength = Len(txtSearch.Text) txtSearch.Focus() End If End With End If End Sub
-
Jul 6th, 2012, 03:01 AM
#12
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
its working but with small error
its highlighting 2 items
-
Jul 6th, 2012, 03:22 AM
#13
Re: Listview Search as type & show in Richtextbox error
Another one 
vb Code:
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged Dim itm As ListViewItem If txtSearch.Text = String.Empty Then RemoveHighlight() Else With ListView1 itm = .FindItemWithText(txtSearch.Text, True, 0, True) If itm IsNot Nothing Then RemoveHighlight() rtb1.Text = System.IO.File.ReadAllText(IO.Path.Combine(scriptPath, itm.Text)) .Items.Item(itm.Index).EnsureVisible() .Items.Item(itm.Index).BackColor = Color.CornflowerBlue .Items.Item(itm.Index).ForeColor = Color.White .Items.Item(itm.Index).Selected = True Else MsgBox("No Record Found!") RemoveHighlight() .Items(0).EnsureVisible() '.Items.Item(0).BackColor = Color.CornflowerBlue '.Items.Item(0).ForeColor = Color.White .Items.Item(0).Selected = True txtSearch.SelectionStart = 0 txtSearch.SelectionLength = Len(txtSearch.Text) txtSearch.Focus() End If End With End If End Sub Private Sub RemoveHighlight() For i As Integer = 0 To ListView1.Items.Count - 1 ListView1.Items.Item(i).BackColor = Color.White ListView1.Items.Item(i).ForeColor = Color.Black Next End Sub
-
Jul 6th, 2012, 03:57 AM
#14
Thread Starter
Junior Member
Re: Listview Search as type & show in Richtextbox error
thanks alot 4x2y
its working find.
u solved the issue n save my day.
thank u very very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|