Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently I have this code to search my directory for md5 hashes but it uses the listbox1.selecteditem to compair with. My problem is how to replace the listbox with a treeview control or to have the treeview act in its place...

any ideas?
VB
Try
  Using scanbox As New TextBox()
  Dim read As String = My.Computer.FileSystem.ReadAllText("virusSig.txt")
  ProgressBar1.Increment(1)
  detected.Text = Conversions.ToString(CheckedListBox1.Items.Count)
                    files.Text = Conversions.ToString(ProgressBar1.Value)
                    scanbox.Text = read.ToString
  Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
                    Dim f As FileStream = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
                        f = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
                        md5.ComputeHash(f)
                        Dim hash As Byte() = md5.Hash
                        Dim buff As StringBuilder = New StringBuilder()
                        Dim hashByte As Byte
                        For Each hashByte In hash
                        buff.Append(String.Format("{0:X2}", hashByte))
                        Next
                        If scanbox.Text.Contains(buff.ToString) Then
                        CheckedListBox1.Items.Add(ListBox1.SelectedItem)
                        End If
                    End Using
                End Using
            Catch ex As Exception
            End Try

thank you in advance!! :)
Posted
Updated 16-Feb-11 18:19pm
v4
Comments
JF2015 17-Feb-11 0:19am    
Added code formatting.

1 solution

After replacing treeview with listbox and necessary binding related code, you can use myTreeView.SelectedNode in place of ListBox1.SelectedItem (You might also need to make sure Datatype to the methods called are changed.)
 
Share this answer
 
Comments
Dale 2012 17-Feb-11 0:34am    
I have changed the listbox1.selecteditem to dirtree1.selectednode but get the exception:

Error 2 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Sub New(handle As System.IntPtr, access As System.IO.FileAccess, ownsHandle As Boolean, bufferSize As Integer, isAsync As Boolean)': Value of type 'System.Windows.Forms.TreeNode' cannot be converted to 'System.IntPtr'.
'Public Sub New(path As String, mode As System.IO.FileMode, access As System.IO.FileAccess, share As System.IO.FileShare, bufferSize As Integer)': Value of type 'System.Windows.Forms.TreeNode' cannot be converted to 'String'. C:\Users\Draco\Desktop\Virus Scanner With Treeview (Working!!!) stripped down\Form1.vb 250 43
Sandeep Mewara 17-Feb-11 0:39am    
I already said: "You might also need to make sure Datatype to the methods called are changed"

Try with string of the selected node.
Dale 2012 17-Feb-11 0:35am    
Will you supply a solution of this code with changes please.. :)
Sandeep Mewara 17-Feb-11 0:40am    
Would be difficult for now. Try. Might give it a shot later.
Dale 2012 17-Feb-11 0:48am    
hey thats better than not at all because honestly im stuck with this

thank you for at least trying this for me.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900