Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3305782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:12:37+00:00 2026-05-17T21:12:37+00:00

I have a byte array that can be very big in size. I want

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:12:37+00:00Added an answer on May 17, 2026 at 9:12 pm

    This is WPF part:

    <DataGrid AutoGenerateColumns="False" Name="dataGrid1" ItemsSource="{Binding Bytes}" ColumnWidth="1*">
            <DataGrid.Columns>
                <DataGridTextColumn Header="1" Binding="{Binding Piece[0]}"></DataGridTextColumn>
                <DataGridTextColumn Header="2" Binding="{Binding Piece[1]}"></DataGridTextColumn>
                <DataGridTextColumn Header="3" Binding="{Binding Piece[2]}"></DataGridTextColumn>
                <DataGridTextColumn Header="4" Binding="{Binding Piece[3]}"></DataGridTextColumn>
                <DataGridTextColumn Header="5" Binding="{Binding Piece[4]}"></DataGridTextColumn>
                <DataGridTextColumn Header="6" Binding="{Binding Piece[5]}"></DataGridTextColumn>
                <DataGridTextColumn Header="7" Binding="{Binding Piece[6]}"></DataGridTextColumn>
                <DataGridTextColumn Header="8" Binding="{Binding Piece[7]}"></DataGridTextColumn>
                <DataGridTextColumn Header="9" Binding="{Binding Piece[8]}"></DataGridTextColumn>
                <DataGridTextColumn Header="10" Binding="{Binding Piece[9]}"></DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    

    And this is the code-behind:

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
    
            // Set the datacontext
            this.DataContext = this;
    
            // Sample array generation
            byte[] array = new byte[138];
    
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = (byte)i;
            }
    
            int length = (int)Math.Ceiling(array.Length / 10m);
    
            Bytes = (from i in Enumerable.Range(0, length)
                    let offset = i * 10
                    let count = offset + 10 > array.Length ? array.Length - offset : 10
                    select new ArrayPiece<byte>(array, offset, count)).ToArray();
        }
    
        ArrayPiece<byte>[] _bytes;
    
        public ArrayPiece<byte>[] Bytes
        {
            get { return _bytes; }
            set { _bytes = value; OnPropertyChanged("Bytes"); }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    
    public struct ArrayPiece<T>
    {
        public T[] Piece { get; set; }
    
        public ArrayPiece(T[] array, int offset, int length) : this()
        {
            Piece = new T[length];
            Buffer.BlockCopy(array, offset, Piece, 0, length);
        }
    }
    

    We use LINQ to split the array in multiple rows and then, with WPF binding, we show the data into the DataGrid.

    EDIT: For the big dimensions of the array I don’t think they are a problem ’cause DataGrid in WPF uses UI Virtualization, and so it just allocates the memory he need to display visible data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte array that represents a complete TCP/IP packet. For clarification, the
I have byte array as input. I would like to convert that array to
Pretty simple scenario. I have a web service that receives a byte array that
Overview: I have an array of 20 byte strings that needs to be stored
I have a very large array of doubles that I am using a disk-based
I have to process a large byte array that is passed to my function.
I have 3 byte arrays in C# that I need to combine into one.
I have a byte array in memory, read from a file. I would like
I have a byte[] array, the contents of which represent a TIFF file (as
I have an EXE loaded into a byte array, and I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.