Stephens' Visual Basic Programming 24-Hour Trainer

Rod Stephens

Mentioned 1

A guide to Visual Basic programming covers such topics as interacting with databases; writing, debugging, and running desktop applications; using Entity Framework to manipulate databases; and using LINQ to Objects to perform complex queries.

More on

Mentioned in questions and answers.

I was designing a form while practicing an exercise from Stephens' Visual Basic Programming 24-Hour Trainer. I have attached an image below:

Exercise Screenshot

I have managed to change the text of both TextBox and LinkLabel to that of "Gullible's Travels" once I select ANY item in the ComboBox 'Simple' DropDown using the following code:

Private Sub cboBooks_SelectionChangeCommitted(ByVal sender _
As Object, ByVal e As EventArgs) _
Handles cboBooks.SelectionChangeCommitted

        Dim senderComboBox As ComboBox = CType(sender, ComboBox)

        ' selected and committed using the SelectionLength property.
        If (senderComboBox.SelectionLength > 0) Then
            txtTitle.Text = "Gullible's Travels"
            txtAuthor.Text = "Matthew Hughes"
            txtISBN.Text = "978-0739419403"
            linklblURL.Text = ""
            txtPages.Text = "401"
            txtYear.Text = "2001"
        End If
    End Sub

GOAL: I wanted to perform the same thing for every item in the ComboBox. In other words, I wanted to capture both mouse and key 'Click' events in order to change the text of the TextBox every time I selected an item on the ComboBox.

Some links such as these has given me the idea of using the Event Handlers: SelectionChanged, MouseDown, KeyDown. I have the impression that some have also recommended to use them simultaneously. However, my confusion arises when it comes to making event handlers (case-by-case or by using a quicker method) for specific items in the Drop Down. I have read recommendations from links like this and this, but have had difficulty implementing them.

Furthermore, I was wondering what the 'names' of these ComboBox items are by default (e.g. 'item1') and how I can change them.

Note: The solution set given with the book uses the following code for each item:

Private Sub Form1_Load() Handles MyBase.Load
        lstBooks.Items.Add(New BookInfo() With
            .Title = "Beginning Database Design Solutions",
            .Author = "Rod Stephens",
            .ISBN = "978-0-470-38549-4",
            .URL = "",
            .Pages = 552,
            .Year = 2009,
            .Cover = My.Resources.db_design

followed by code with 'bi' as a filler. I would appreciate if someone could fill me in with what purpose this is used for and its proper usage.

 Private Sub booksListBox_SelectedIndexChanged() Handles lstBooks.SelectedIndexChanged
        Dim bi As BookInfo = DirectCast(lstBooks.SelectedItem, BookInfo)
        txtTitle.Text = bi.Title
        txtAuthor.Text = bi.Author
        txtISBN.Text = bi.ISBN
        llURL.Text = bi.URL
        txtPages.Text = bi.Pages.ToString()
        txtYear.Text = bi.Year.ToString()
        picCover.Image = bi.Cover
    End Sub