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
105
DataBind on WinGrid dose not refresh child bands
posted

hi,

Im binding the grid to a business object witch contain a list of other object (like defined in the code below)

Im currently updating the list of sub objects and their properties and call the grid DataBind in order to update the display

but the grid dose not update the display and even dose not call the InitializeRow event

the only "ugly" way i found to refresh the display is by calling the code as i wrote in button2_Click handler below

the problem with this way to refresh the grid is that all the expended nodes will collapse

is this a problem in DataBind method or am i doin somthing wrong?

 

this is a simple tester i wrote to recreate the problem.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestBind
{
    public partial class Form1 : Form
    {
        private List<Moo> moos;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            moos = new List<Moo>();
            moos.Add(new Moo("yoyoyo"));

            mooBindingSource.DataSource = moos;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            moos[0].Moos.Add(new SubMoo("asdasd"));

            ultraGrid1.DataBind();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            mooBindingSource.DataSource = typeof(Moo);
            ultraGrid1.DataBind();
            mooBindingSource.DataSource = moos;
            ultraGrid1.DataBind();
        }
    }

    public class Moo
    {
        private List<SubMoo> moos;
        private string name;

        public Moo(string name)
        {
            this.name = name;
            moos = new List<SubMoo>();
        }

        public string Name
        {
            get { return name; }
        }

        public List<SubMoo> Moos
        {
            get { return moos; }
        }
    }

    public class SubMoo
    {
        private string name;

        public SubMoo(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
        }
    }
}

thanks, moshe