Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Do you bind to an indexer?. can you show us how your DataList Property looks like?</p> <p>i did the same a while ago with an indexed property.</p> <pre><code> public SomeObjectWithIndexer DataList {get; set;} public class SomeObjectWithIndexer { public string this { get { ... } set { ... }//&lt;-- you need this one for TwoWay } } </code></pre> <p>EDIT: the reason that you cant edit your Property, is that you try to edit a "double field". one workaround would be to wrap your double into a class with INotifyPropertyChanged.</p> <pre><code>public class DataListItem { public double MyValue { get; set;}//with OnPropertyChanged() and stuff } </code></pre> <p>then you can use a</p> <pre><code>ObservableCollection&lt;DataListItem&gt; </code></pre> <p>and you can edit your value. the question wether the index are always the same stay still around :)</p> <pre><code>Binding binding = new Binding(string.Format("DataList[{0}].MyValue", n++)); </code></pre> <p>EDIT2: working example: just to show twoway is working</p> <pre><code>public class DataItem { public string Name { get; set; } public ObservableCollection&lt;DataListItem&gt; DataList { get; set; } public DataItem() { this.DataList = new ObservableCollection&lt;DataListItem&gt;(); } } </code></pre> <p>Wrapper for double:</p> <pre><code>public class DataListItem { private double myValue; public double MyValue { get { return myValue; } set { myValue = value; }//&lt;-- set breakpoint here to see that edit is working } } </code></pre> <p>usercontrol with a datagrid</p> <pre><code>&lt;UserControl x:Class="WpfStackoverflow.IndexCollectionDataGrid" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"&gt; &lt;DataGrid ItemsSource="{Binding MyList}" AutoGenerateColumns="False"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" /&gt; &lt;DataGridTextColumn Header="Index1" Binding="{Binding Path=DataList[0].MyValue, Mode=TwoWay}" /&gt; &lt;DataGridTextColumn Header="Index2" Binding="{Binding Path=DataList[1].MyValue, Mode=TwoWay}" /&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/UserControl&gt; </code></pre> <p>.cs</p> <pre><code>public partial class IndexCollectionDataGrid : UserControl { public IndexCollectionDataGrid() { InitializeComponent(); this.MyList = new ObservableCollection&lt;DataItem&gt;(); var m1 = new DataItem() {Name = "test1"}; m1.DataList.Add(new DataListItem() { MyValue = 10 }); m1.DataList.Add(new DataListItem() { MyValue = 20 }); var m2 = new DataItem() { Name = "test2" }; m2.DataList.Add(new DataListItem() { MyValue = 100 }); m2.DataList.Add(new DataListItem() { MyValue = 200 }); this.MyList.Add(m1); this.MyList.Add(m2); this.DataContext = this; } public ObservableCollection&lt;DataItem&gt; MyList { get; set; } } </code></pre> <p>i hope you get in the right direction with this example. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload