locked
selected one value from list view selected row

    Question

  • hi

    i have a list view that it have 10 columns.

    i select one row from it.

    i want when i selected one row then return on this row column 5 value.

    example:

    row     Name     family     age     id     country  ....

    1         jack        black      38       3       usa    ...

    2        tom          sier        22      4        uk    ....

    3        brad          pit          50     5         usa   ....

    .

    .

    ...

    when i select row 2 , i want return to me 4(column5)

    tank you very much.please give me answer.i asked you many question in my before post  but you dont answer to me.  :(

    i love microsoft but he dosnt love me :(


    Amir Ameri


    • Edited by AMIR ameri Saturday, December 06, 2014 6:33 AM
    Saturday, December 06, 2014 5:57 AM

Answers

  • Post some code on how you are getting stuff in the listview.

    • Marked as answer by AMIR ameri Monday, December 08, 2014 9:49 PM
    Sunday, December 07, 2014 1:47 PM
  • hi

    my problem solved by dynamic class:

    private async void mylist2_SelectionChanged(object sender, SelectionChangedEventArgs e)

            {

                dynamic a = mylist2.SelectedItems[0];

                MessageDialog msg2 = new MessageDialog(a.BName.ToString());

                await msg2.ShowAsync();


    Amir Ameri

    • Marked as answer by AMIR ameri Tuesday, December 09, 2014 6:36 AM
    Monday, December 08, 2014 9:47 PM

All replies

  • hi

    i have a list view that it have 10 columns.

    i select one row from it.

    i want when i selected one row then return on this row column 5 value.

    example:

    row     Name     family     age     id     country  ....

    1         jack        black      38       3       usa    ...

    2        tom          sier        22      4        uk    ....

    3        brad          pit          50     5         usa   ....

    .

    .

    ...

    when i select row 2 , i want return to me 4(column5)

    tank you very much.please give me answer.i asked you many question in my before post  but you dont answer to me.  :(



    Amir Ameri

    Sunday, December 07, 2014 7:11 AM
  • I assumption your ListView source structure like below: 

         private void lv_main_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                personal selectItem = (personal)lv_main.SelectedItem;
    
                int id = selectItem.id;
    
            }
    
            public class personal
            {
                public string Name { get; set; }
                public string family { get; set; }
                public int age { get; set; }
                public int id { get; set; }
    
    
    
            }

    • Marked as answer by AMIR ameri Monday, December 08, 2014 9:47 PM
    Sunday, December 07, 2014 10:21 AM
  • Post some code on how you are getting stuff in the listview.

    • Marked as answer by AMIR ameri Monday, December 08, 2014 9:49 PM
    Sunday, December 07, 2014 1:47 PM
  • hi

    i used your source structure and it was ok.

    but in this method i cant add row or inert row to my listview.

    just i can add one row in my listview and when i want add item to my list , first row data has updated.

    i want add and insert my list view

    please help me about this.


    Amir Ameri

    Sunday, December 07, 2014 2:49 PM
  • If you want remove/add ListView items.

    You may need using ObservableCollection class to implement add/remove feature.

    Because ObservableCollection have implement INotifyPropertyChanged interface.

    So if you add or remove Item in ObservableCollection,

    Listview will dynamical update.

                ObservableCollection<personal> oc = new ObservableCollection<personal>(){
                    new personal(){Name="kevin",age=18,id=1},
                    new personal(){Name="julia",age=18,id=2},
                    new personal(){Name="carol",age=18,id=3}
                };
                oc.Add(new personal(){Name="Nathaniel", age=23, id=0});
                oc.Add(new personal() { Name = "Eason", age = 26, id = 9 });
                oc.Add(new personal() { Name = "Rick", age = 22, id = 8 });
    
                //remove kevin
                oc.RemoveAt(0);
    
                //remove Eason
                oc.RemoveAt(3);

     
    Sunday, December 07, 2014 5:33 PM
  • when i type obs.. then appear ObservableDictionary not ObservableCollection

    Amir Ameri

    Sunday, December 07, 2014 6:29 PM
  • No, that is different thing between them.

    You need using System.Collections.ObjectModel;


    Monday, December 08, 2014 3:22 AM
  • hi

    my problem solved by dynamic class:

    private async void mylist2_SelectionChanged(object sender, SelectionChangedEventArgs e)

            {

                dynamic a = mylist2.SelectedItems[0];

                MessageDialog msg2 = new MessageDialog(a.BName.ToString());

                await msg2.ShowAsync();


    Amir Ameri

    • Marked as answer by AMIR ameri Tuesday, December 09, 2014 6:36 AM
    Monday, December 08, 2014 9:47 PM
  • hi

    my problem solve by this code:


      

            <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" >

                            <Grid.ColumnDefinitions>

                                <ColumnDefinition></ColumnDefinition>

                                <ColumnDefinition></ColumnDefinition>

                            </Grid.ColumnDefinitions>

                           

                            <ListViewItem  Content="{Binding BAge}"  Grid.Column="0" Width="auto"/>

                            <ListViewItem  Content="{Binding BName}"  Grid.Column="1" Width="auto"/>

                           

                        </Grid>

                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

          

        </Grid>

    </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 , BName="Amir" } };

              

                if (i == listt2.Count) i = 0;

               mylist2.Items.Add(listt2[i++]);

            }

            private async void mylist2_SelectionChanged(object sender, SelectionChangedEventArgs e)

            {

                dynamic a = mylist2.SelectedItems[0];

                MessageDialog msg2 = new MessageDialog(a.BName.ToString());

                await msg2.ShowAsync();

              

            }

           

            }

        }


    Amir Ameri

    Monday, December 08, 2014 9:49 PM