JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the DisplayMember and ValueMember Properties

If you take a look at the checked list box at lower left in the DataBinding example in Figure 21.3, you'll note that this control is displaying the authors' last names. However, when the user makes a selection in the checked list box, the program displays the author's ID value in the text box just below the checked list box, as you can see in Figure 21.3.

As we know, list boxes use DisplayMember and ValueMember properties to bind to a specific data field. In the DataBinding example, I've bound the checked list box's DisplayMember property to the authors.au_lname field, and the ValueMember property to the authors.au_id field. That means the program will show the author's last name in the checked list box, but when the user clicks an author in that control, I'll use the control's SelectedValue property to get the actual author's ID value and display it:

Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender _
    As System.Object, ByVal e As System.EventArgs) Handles _
    TextBox2.Text = "Selected ID: " & CheckedListBox1.SelectedValue
End Sub

In this way, as discussed earlier in this chapter, the checked list box can display user-friendly names, while actually returning code-friendly ID values.

That completes the DataBinding example on the CD-ROM. But there's more to cover—for example, what if the user wanted to edit the data in bound controls and send the new data back to the data store? In that case, you'd want a data entry form—and Visual Basic has a great tool to let you create data entry forms automatically—the Data Form Wizard.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor