MAC
MAC

Reputation: 6577

binding data into the List box

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?

Upvotes: 0

Views: 253

Answers (1)

Julien Poulin
Julien Poulin

Reputation: 13015

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
  ));
}

Upvotes: 3

Related Questions