Winforms, databinding, Listbox and textbox
One of the easiest way, I guess, would be to use a BindingSource
, setting it as the ListBox.DataSource
property to your BindingSource
on design.
- Drop a
BindingSource
on your form; - Set your
ListBox.DataSource
property to yourBindingSource
; - Set your
ValueMember
andDisplayMember
properties just like you're actually doing; - Make your
DataBinding
for yourTextBox
control, and use yourBindingSource
as the source, using yourMyItem.Comment
property; - Assign your
List(Of MyItem)
to yourBinding.DataSource
property; - Your TextBox should follow the
CurrencyManager.CurrentItem
's Comment property, that is, the currentlyListBox.SelectedItem
.
Indeed, you would perhaps need to implement the INotifyPropertyChanged
interface to make it work properly.
But if this all work perfect with the SelectValue, why don't you just use it?