locked
just value from listview items

    Question

  • hi

    my code is:

                

     

     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="180*"/>
                <ColumnDefinition Width="456*"/>
                <ColumnDefinition Width="75*"/>
                <ColumnDefinition Width="336*"/>
                <ColumnDefinition Width="319*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="32*"/>
                <RowDefinition Height="171*"/>
                <RowDefinition Height="53*"/>
            </Grid.RowDefinitions>

            <Button Content="Button" HorizontalAlignment="Left" Height="51" Margin="7,66,0,0" VerticalAlignment="Top" Width="117" Click="Button_Click" Grid.Row="2" Grid.Column="1"/>
            <ListView x:Name="mylist2" SelectionChanged="mylist2_SelectionChanged" Background="#FF360808" Grid.Row="1" Margin="10,0,20,20" Grid.Column="3">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Width="auto" >



                            <ListViewItem  Content="{Binding BAge}"   Width="auto"/>

                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
           
        </Grid>

    ------------------------------------------------------------

     public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }

           // Data source.

            
            int i;
      
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                      List<object> listt2 = new List<object>() { new { BAge = 28 } };
               
                if (i == listt2.Count) i = 0;
               mylist2.Items.Add(listt2[i++]);

            }

            private async void mylist2_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                MessageDialog msg2 = new MessageDialog(mylist2.SelectedValue.ToString());

                await msg2.ShowAsync();
            }
            }
        }

    -------------------------------------------

    when message box appear show  { BAge = 28 }

    i want just show 28

    what is code for this?

    tank you very much


    Amir Ameri

    Monday, December 08, 2014 3:27 PM

Answers

  • Here is a solution but I would recommend to use a class for your objects in the list.

     private async void mylist2_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                dynamic a = mylist2.SelectedItems[0];
                MessageDialog msg2 = new MessageDialog(a.BAge.ToString());
              
                await msg2.ShowAsync();
            }

    Regards, Markus


    • Edited by Zorro14 Monday, December 08, 2014 6:31 PM
    • Proposed as answer by Zorro14 Monday, December 08, 2014 6:32 PM
    • Marked as answer by AMIR ameri Monday, December 08, 2014 9:43 PM
    Monday, December 08, 2014 4:48 PM

All replies