'VB.Net Weird databound listbox behavior
I have a databound listbox that's behaving rather oddly.
Code for initializing the form with the listbox:
Private Sub FormManageProjects_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Activate()
Me.ProjectTableAdapter.Fill(Me.AllAppData.Project)
ProjectsList.SelectedIndices.Clear()
btnOpen.Enabled = False
btnDelete.Enabled = False
End Sub
The SelectedItem property of ProjectsList is bound to a string "Name" and the SelectedValue property is bound to an integer "ID". I have "Open" and "Delete" buttons that are initially disabled but are enabled as soon as one of the list items is selected.
Code enabling buttons:
Private Sub ProjectsList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ProjectsList.SelectedIndexChanged
btnOpen.Enabled = True
btnDelete.Enabled = True
End Sub
I've populated my database with three projects. Project 1, Project 2, and Project 3.
Everything appears fine at first. I select one of the projects and the two buttons are enabled. I select a different project and the displayed name of the previously selected project changes to System.Data.DataRowView and I can't figure out why. If I pull up a DGV bound to the same data I see that the data in the database has not actually changed. Any ideas about what might be causing this behavior? I've attached a few screenshots so you can see the changes. Screenshot showing freshly initialized ListBox Screenshot showing selected list item and change in button state Screenshot showing a different list item selected, and the changed display name of the previously selected list item.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
