I am trying to get data from a Gridview that I created in XAML.
<ListView Name="chartListView" selectionChanged="chartListView_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="250"/>
<GridViewColumn Header="Type" DisplayMemberBinding="{Binding Type}" Width="60"/>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" Width="100"/>
</GridView>
</ListView.View>
</ListView>
I saw this code: -
GridViewRow row = GridView1.SelectedRow;
TextBox2.Text = row.Cells[2].Text;
However, my problem is that my GridView is created in XAML and is not called, i.e. I can’t (or don’t know how) create a link to "gridview1" and therefore cannot access the objects inside it.
Can I name or link to my gridview from either C # or XAML to use the code above?
Secondly, can I then access the elements of the array by name instead of index, for example: -
TextBox2.Text = row.Cells["ID"].Text
Thanks for any help.
source
share