tags:

views:

78

answers:

1

how to bind the data from the text box into a List box in Silver light? I have 5 text boxes and at the time clicking the save button, the list box will flll with the data that displayed in the text boxes. How it will be done in silver light?

+4  A: 

Something like this will do what you want:

Xaml:

<StackPanel>
  <ListBox x:Name="lbStrings"></ListBox>
  <TextBox x:Name="tb1" Width="50"></TextBox>
  <TextBox x:Name="tb2" Width="50"></TextBox>
  <TextBox x:Name="tb3" Width="50"></TextBox>
  <TextBox x:Name="tb4" Width="50"></TextBox>
  <TextBox x:Name="tb5" Width="50"></TextBox>
  <Button Click="Save" Content="Save" />
</StackPanel>

Code-behind:

private void Save(object sender, RoutedEventArgs e) {
  //lbStrings.Items.Clear(); //uncomment if needed
  lbStrings.Items.Add(
    string.Format("{0} - {1} - {2} - {3} - {4}",
    tb1.Text,
    tb2.Text,
    tb3.Text,
    tb4.Text,
    tb5.Text
  ));
}
Julien Poulin
but how to display these 5 text boxes data in a single line of the list box?
Dilse Naaz
Thanks dear for ur answer
Dilse Naaz