Bind TextBox to Selected Item of ListBox

  • Thread starter Thread starter OldNewbie
  • Start date Start date
O

OldNewbie

Hello All

I have a textbox control. I would like this text box to automatically
update to contain the currently selected item located in a listbox
which is on the same form.

Do I need a CurrencyManager for this? Can this be done just by
manipulating the databindings properties of the textbox? If so, please
do give me some hints as to the syntax I would use to fill in that
field on the property panel - everything I try is rejected.

Disclaimer: No this is NOT my homework. I'm 45 years old, new to
CSharp and quite capable of digging most things up on the net for
myself. I just cannot seem to make this work. A few code snippets
would be much appreciated. Obviously I could code a manual procedure
for this - but hey CSharp is supposed to automate this sort of thing
(I think) and I wanna know how its done. I have seen all of the
dataset binding examples - nothing seems to work on the listbox to
textbox pair.

Cheers
Old Newbie
 
From one old git to another :-)

You could use the SelectedIndexChanged event on the listbox to update the
textbox:-
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs
e)

{

this.textBox1.Text = this.listBox1.SelectedItem.ToString();

}

Regards,

Gras
 
Ahh.... of course. So simple! Thank you.

Eventually I'm going to have to get to grips with the data binding and
CurrencyManager stuff but that can be put off to another day.

Cheers muchly
OldNewbie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Binding listbox items 1
Problem with WPF ListBox 5
Binding object 1
Access Cannot select items in listbox 1
Update bound ListBox 6
ListBox WPF and Binding 2
Binding a Textbox to a property 5
Problem binding DataSet to a ListBox 4

Back
Top