Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
570
AddNewRow Property of a UltraWinGrid disappears when deserializing a serialized UltraDataSource
posted

Hi all !

Szenario:
A UltraWinGrid has a UltraDataSource as DataSource. The UltraDataSource structure consists of a root band and a set of child bands. Users are allowed to add new row of data for all child band but not the the root band.

Therefore each child band (UltraGridBand) in the UltraWinGrid has the following properties

    Override -> AllowAddNew = FixedAddRowOnBottom
    Override -> AllowDelete = True
   
Problem:   
When running a form with the gird, all "add new row" rows will be displayed. But when deserializing a (binary) serialized UltraDataSource  the associated UltraWinGrid does not show any "add new row" in the child bands.

You can reproduce this behavior by doing 4 steps:

Step 0 : Create a project with a form.
Step 1 : Build up a UltraDataSource with a root band and some child bands.
Step 2 : Create a UltraWinGrid and associate it with the UltraDataSource.
Step 3 : Allow AddNew behavior "FixedAddRowOnBottom" of each child band via child bands override properties.
Step 4 : Add two buttons to the form and combine each button click event as displayed below:

        private  byte[ datasourceAsByteStream = null;


        private void ultraButton1_Click(object sender, EventArgs e) {
            datasourceAsByteStream = this.SerializeIt(ultraDataSource1);          
        }

        private void ultraButton2_Click(object sender, EventArgs e) {
            this.ultraDataSource1.Rows.Clear();
            this.DeserializeIt(this.ultraDataSource1, datasourceAsByteStream);
        }

        private byte[ SerializeIt(UltraDataSource ds) {
            BinaryFormatter binFormatter = null;
            MemoryStream    memoryStream = null;
            byte[                 bytes = null;

            if (ds != null) {
                try {
                    memoryStream = new MemoryStream();
                    ds.SaveAsBinary(memoryStream, true);
                   
                    long ms = memoryStream.Length;
                    bytes   = memoryStream.ToArray();
                    long lb = bytes.Length;

                } catch (Exception e) {
                    Console.Out.WriteLine("Couldn't serialize the data source!");
                }
            }
            return bytes;          
        }

      
        private bool DeserializeIt(UltraDataSource ds, byte[ bstream) {
            MemoryStream memoryStream = null;
            bool               loaded = false;

             if ((ds != null) && (bstream != null)){
                try {              
                    memoryStream = new MemoryStream();
                    memoryStream.Write(bstream, 0, bstream.Length);                  
                    memoryStream.Position = 0;                                      
                    ds.LoadFromBinary(memoryStream, true);
                    loaded = true;
                } catch (Exception e) {
                    Console.Out.WriteLine("Couldn't deserialize the data source! " + e.Message);
                }
            }

Any advice or ideas you might have, would be very welcome. Thanks in advance !

Kind regards,

Claus 

  • 469350
    Verified Answer
    Offline posted

    Hi Claus,

        I'm not sure that converting the stream into a Byte Array is great idea. So I tried just saving and loading the data source to a stream. So my code looks like this:

            private MemoryStream memoryStream = null;

            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                e.Layout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.FixedAddRowOnBottom;
                e.Layout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.FixedAddRowOnBottom;
            }

            private void button1_Click(object sender, EventArgs e)
            {
                if (this.memoryStream == null)
                    this.memoryStream = new MemoryStream();

                this.ultraDataSource1.SaveAsBinary(memoryStream);           
            }

            private void button2_Click(object sender, EventArgs e)
            {
                if (this.memoryStream != null)
                {
                    this.memoryStream.Position = 0;
                    this.ultraDataSource1.LoadFromBinary(memoryStream);
                }
            }

    But I get the same results you describe. I can't see why it's happening. I recommend that you Submit an incident to Infragistics Developer Support so they can check it out.