I’ve been trying to bind DataGridTextColumns column-wise to arrays (int[] I think) and have been unsuccessful. Nothing I’ve found on msdn, stackoverflow etc has been particularly helpful .
<DataGrid AutoGenerateColumns="False" VerticalAlignment="Top" Margin="0,47,0,0" Height="351" Name="dataGrid1" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Slave Address" Width="100" Binding="{Binding SlaveAddressValues}"/>
<DataGridTextColumn Header="Meter Readings" Width="100" Binding="{Binding MeterReadingValues}"/>
</DataGrid.Columns>
</DataGrid>
I’ve tried a number of things including putting binding in with datagrid instead or as well as datagridtextcolumns (itemsource etc), defining datacontext in code (I’d like to keep as much as possible out of code for mvvm reasons), using paths and sources, and also trying to combine my two arrays in a class (which isn’t really what I want anyway). However nothing has worked in getting even the following simple test case to properly bind with the datagrid.
private int[] SlaveAddressValues = { 0, 0, 0, 0 };
private int[] MeterAddressValues = { 2, 2, 2, 3 };
Anyone got any ideas?
Right, maybe I should have put my solution here but it was a bit long so I put it as an answer. it’s one of many ways anyway so post another answer if you feel so inclined.
Need to bind to a single source
create
Bind the DataGrid to Adddress
Then on the columns bind the path to Slave and Meter