none
How to get cell values in a listview in C# WPF-urgent

    Question

  • how can I do following

     

     

    int NumberofChildInALearningStory = SelectedchildInfoListView1.Items.Count;

     

    for (int i = 0; i < NumberofChildInALearningStory; i++)
           {
              int ChildId = **Need to get SelectedchildInfoListView1  row[i] column[1] value**

          }

     

    Can Any one please help me . This is urgent.

     

    Thanks.

     

    how can I do following

     int NumberofChildInALearningStory = SelectedchildInfoListView1.Items.Count;

     

    for (int i = 0; i < NumberofChildInALearningStory; i++)
           {
              int ChildId = **Need to get SelectedchildInfoListView1  row[i] column[1] value**

          }

     

    Can Any one please help me . This is urgent.

     

    Thanks.

     

    Monday, July 12, 2010 3:39 AM

All replies

  • Is your listView data bound to some data model? Can you show XAML please?


    God bless you!
    Monday, July 12, 2010 3:44 AM
  •  <ListView Grid.Column="1" Grid.Row="4" Grid.RowSpan="2" Margin="0,6,30,29" Name="SelectedchildInfoListView1" >
                                        <ListView.View >
                                            <GridView >
                                                <GridViewColumn DisplayMemberBinding="{Binding child_ID}" Width="60"/>
                                                <GridViewColumn  DisplayMemberBinding="{Binding family_name}" Width="auto"/>
                                                <GridViewColumn  DisplayMemberBinding="{Binding given_name}" Width="200"/>
                                               


                                            </GridView>
                                        </ListView.View>
                                    </ListView>

     

    data will added as follows

    SelectedchildInfoListView1.Items.Add(new { child_ID = SelectedChildID, family_name = familyname, given_name = givenname });

    Monday, July 12, 2010 4:24 AM
  • It isn't common practice to work with ListView in that way. 

    You should create separate entity (class) MyDataEntity with properties ChildID, FamilyName and GivenName. After that you should create ObservableCollection<MyDataEntity> EntitiesList and data bind ListView to this EntitiesList.

    After that you will be able to enumerate EntitiesList in code, perform some magic and changes will be propagated to ListView due to binding mechanism.

    If this doesn't help or you need code sample, please let us know. If this is correct answer mark it as "Asnwer" please.


    God bless you!
    Monday, July 12, 2010 4:36 AM
  • Hi Tillias,

    Thanks for your advice; I managed to do the work as I want. But I would appreciate very much if you could send me some sample code for your proposal.

     

    Thanks.

     

    Monday, July 12, 2010 10:39 AM