JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the DisplayMember and ValueMember Properties

As discussed in the In Depth section of this chapter, the DisplayMember and ValueMember properties let you display data in a user-friendly way. In the DataBinding example, there's a checked list box that lets the user select an author from the authors table of the pubs database by last name—but we want to get the ID of the author the user has selected. To do this, I set the checked list box's DisplayMember property to the au_lname field to display the author's last name in the control, and the ValueMember property to the au_id field so that when the user makes a selection, you can use the SelectedValue property of the control to get the selected author's ID:

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.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor