By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,361 Members | 3,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,361 IT Pros & Developers. It's quick & easy.

Bind TextBox to Selected Item of ListBox

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"OldNewbie" <No****@NoSpam.com> wrote in message
news:4e********************************@4ax.com...
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.

Nov 17 '05 #2

P: n/a
On Sun, 6 Nov 2005 11:46:23 +0100, "La Grasserie"
<newsatthe-farrs.com> wrote:

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
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

"OldNewbie" <No****@NoSpam.com> wrote in message
news:4e********************************@4ax.com.. .
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.


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.