Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a list box and a button click event ,when i select an item in the listbox and click on the button then the list item should appear in the text box...please help with the code
Posted
Updated 13-Oct-13 23:19pm
v2
Comments
Alexander Dymshyts 14-Oct-13 5:03am    
What did you try to do?
Member 10321925 14-Oct-13 5:08am    
tb1.Text = listbox1.SelectedItem.ToString();
Alexander Dymshyts 14-Oct-13 5:19am    
So what is the problem?
Member 10321925 14-Oct-13 5:25am    
System.Windows.Controls.ListBoxItem: item name i'm getting like this in my textbox but i need only itemname to appear on my text box
Alexander Dymshyts 14-Oct-13 5:32am    
Show your code where you add items to listbox

1 solution

This code works for me
C#
private void TextBox_Loaded(object sender, RoutedEventArgs e)
{
    listbox1.Items.Add(1);
    listbox1.Items.Add(2);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    tb1.Text = listbox1.SelectedItem.ToString();
}
 
Share this answer
 

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