Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to replace listbox value using Textbox value?
Posted
Updated 23-May-11 23:07pm
v2

1. It's kind of similar or close to what you asked yesterday[^].

2. You are hardly sharing any effort if done. Posting just a question and expecting code for it.

3. It's pretty simple. Surely you are a beginner, yet a simple start, book/tutorial would easily teach you how to proceed.

4. Try first, formulate your question properly and tag it correctly.

==========

Based on your history, looks like you are working on Winforms. For the above said scenario, all you need to do is find the selected value of the Listbox in your button click event and then put that in the textbox.

Try!
 
Share this answer
 
Comments
Sandeep Mewara 5-May-11 3:03am    
What do you mean you cannot? based on the level of question, who in world has issues posting the related code?
Sandeep Mewara 5-May-11 3:03am    
Good to know. :doh:
Sergey Alexandrovich Kryukov 5-May-11 16:46pm    
Sandeep, the answers were too bad. I'm not sure if any of them work. I finally added my answer to the yesterday's question.
My 5 for this answer.

Please see the past answer and let me look at the answers here...
--SA
Sandeep Mewara 5-May-11 23:55pm    
Virtual upvoted!? :)

Saw you answer. :thumbsup:
Sergey Alexandrovich Kryukov 5-May-11 23:58pm    
Did I virtually mean 5? That's right, now late-bound :-)
--SA
This is how to do it:

this.myButton.Click += (sender, eventArgs) => {
   int index = MyListBox.SelectedIndex;
   if (index < 0) return;
   MyListBox.Items.Insert(index, myButton.Text);
   MyListBox.SelectedIndex = index;
   MyListBox.Items.RemoveAt(index + 1);
};


I suspect many other experts did not test the answers. Some would not even compile.
I tested mine!

—SA
 
Share this answer
 
Comments
Sandeep Mewara 5-May-11 23:54pm    
I am sure based on OPs question and knowledge, he will be confused on the use of Anonymous method you did here! :)

My 5 for putting in effort in giving the full code.
Sergey Alexandrovich Kryukov 5-May-11 23:57pm    
Thank you. I don't care about anonymous -- not using it is just typing more letters :-)
Who really wants to understand will certainly understand; and the more good ideas the better.
--SA
Sandeep Mewara 6-May-11 0:00am    
Who really wants to understand will certainly understand; and the more good ideas the better.
Fully agree! :)
Sergey Alexandrovich Kryukov 6-May-11 0:08am    
:-)
try this Code

MIDL
foreach (ListItem l in ListBox1.Items)
            {
                if (l.Selected == true)
                {
                    l.Text = TextBox1.Text;
                }
            }
 
Share this answer
 
Comments
Kim Togo 5-May-11 2:18am    
My 5. That will work.
Mahendra.p25 5-May-11 2:19am    
Thanks Kim

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900