Hi,
I have a byte array that can be very big in size. I want to bind it to a grid with a fixed size of column, lets say 10.
so the first 10 bytes will be on the first row, the 10 next bytes will be on the second row... until the end of the array.
I need to be able to edit any bytes and this need to be reflected into the array. My byte array needs to stay a simple byte array.
All that using WPF C#.
Thank you for your help!
EDIT :
Actually, AS-CII's solution doesn't save updated values into the original array. I modified the example to meet this criteria :
<DataGrid AutoGenerateColumns="False" Name="dataGrid1" ItemsSource="{Binding Bytes}" ColumnWidth="1*">
<DataGrid.Columns>
<DataGridTextColumn Header="1" Binding="{Binding [0]}"></DataGridTextColumn>
<DataGridTextColumn Header="2" Binding="{Binding [1]}"></DataGridTextColumn>
<DataGridTextColumn Header="3" Binding="{Binding [2]}"></DataGridTextColumn>
<DataGridTextColumn Header="4" Binding="{Binding [3]}"></DataGridTextColumn>
<DataGridTextColumn Header="5" Binding="{Binding [4]}"></DataGridTextColumn>
<DataGridTextColumn Header="6" Binding="{Binding [5]}"></DataGridTextColumn>
<DataGridTextColumn Header="7" Binding="{Binding [6]}"></DataGridTextColumn>
<DataGridTextColumn Header="8" Binding="{Binding [7]}"></DataGridTextColumn>
<DataGridTextColumn Header="9" Binding="{Binding [8]}"></DataGridTextColumn>
<DataGridTextColumn Header="10" Binding="{Binding [9]}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Notice the only change was Array[0] to [0]
public struct ArrayPiece<T>
{
private T[] m_Data;
private int m_Offset;
private int m_Length;
public T this[int index] {
get{
return m_Length > index? m_Data[m_Offset + index] : default(T);
}
set{
if(m_Length > index)
m_Data[m_Offset + index] = value;
}
}
public ArrayPiece(T[] array, int offset, int length)
: this()
{
m_Data = array;
m_Offset = offset;
m_Length = length;
}
}
And this is the new ArrayPiece.
With those change, when, within the UI, a value is changed, it is updated to the original array.
There is one problem with this : If the last ArrayPiece only have 8 elements instead of 10, the 2 left elements will show 0 in the DataGrid unlike when using an array directly. I tried implementing Length and LongLength property without success. If I throw index out of bound, it is not caught.
Thanks!