0
votes

I am building a program to manage my DVD collection in visual basic (8) I read a file into listbox1 which contains all my data which has the following format: (title of DVD)(4 digit) House On Haunted Hill1049 Walking Dead(Season 1 Disc 1)2022 Night Of The Living Dead2044 Dawn Of The Dead3011 I Spit On Your Grave1010

I search listbox1 for any matches (minus the last 4 numbers) The matching titles are thrown into listbox2 and the 4 digit numbers are put into listbox3 I would like to color the items in listbox2 where a "3" is found in listbox2.

If I put the 4 digit in with the title I can change the color using code found here.

so if I search for 'dead' I would get in listbox2 Walking Dead(Season 1 Disc 1) (this is in black since it doesn't start with 3) Night Of The Living Dead (this is in black since it doesn't start with 3) Dawn Of The Dead (this item would be in green, since the value in listbox3 is 3011

Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem e.DrawBackground()

If ListBox1.Items(e.Index).ToString() = "herp" Then

    e.Graphics.FillRectangle(Brushes.LightGreen, e.Bounds)
End If
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), e.Font, Brushes.Black, New System.Drawing.PointF(e.Bounds.X, e.Bounds.Y))
e.DrawFocusRectangle()

End Sub

The above code I found on this site but I can't find how to use two listboxes with it.

Sorry for my poor explaination - I just play with visual basic - I school I learned fortran, cobol and RPGII

1

1 Answers

0
votes

I kept messing with the IF statement - and found that I could reference the other listbox and was able to affect the listbox in question.

If Mid(ListBox3.Items(e.Index).ToString(), 1, 1) = "3" Then

that way it only looked at the first digit of the four numbers and if it hit may match the listbox colored only the title of the dvd.