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
150
How to dynamically add child data?
posted

I will do my best to explain this senario.

I am using an UltraGrid to display data of which I will have no knowedge of at run time. I am parsing an xml file that will create a list of queries and their relations.

  1.  Call the first query right away and add the resulting datatable to a dataset.
  2. create a Child table(place holder for a child data) that has the same first column type as the parent table. Than create a datarelation object to create a relationship between the two tables and add the child and relation object to the dataset.
  3. Add the dataset to the UltraGrid.
  4. Now, when I click the expand button, using the BeforeRowExpand event, I get the related query from my query list, and call for the new child DATA from the database.
  5. I use the new DATA to update the child table inside the dataset. I append the missing column and than add the data to the child table.

when I run through this squence of events the child bands do not display. Is it possible to add child data to the UltraGrid and display it? Am I doing this out of order somehow? Does the data have to be there before the expand event fires? Can I get any alternate suggestions? My biggest problem seems to be that Data is completely dynamic.

Parents
No Data
Reply
  • 37774
    Suggested Answer
    posted

    I seem to recall an issue that was fixed a while ago regarding populating the child band in the BeforeRowExpanded event, so depending on your version this may be the same issue.  I hacked together a quick test, which seemed to work for me:

    private static DataTable GetTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Col 1", typeof(string));
        dt.Columns.Add("Col 2", typeof(int));
        dt.Columns.Add("Col 3", typeof(decimal));
        dt.Columns.Add("Col 4", typeof(bool));
        dt.Columns.Add("Col 5", typeof(DateTime));

        for (int i = 0; i < 30; i++)
        {
            dt.Rows.Add(new object[] { "Row " + i.ToString(), i, i * 1.234m, i % 2 == 0, DateTime.Now.AddYears(i) });
        }

        return dt;
    }

    public Form1()
    {
        InitializeComponent();

        DataSet ds = new DataSet();
        DataTable dt = GetTable();
        DataTable dt2 = new DataTable();
        dt2.Columns.Add("Col 1");

        ds.Tables.Add(dt);
        ds.Tables.Add(dt2);
        ds.Relations.Add(dt.Columns[0], dt2.Columns[0]);
        this.ultraGrid1.DataSource = ds;
    }

    private bool hasPopulatedChildBand;
    private void ultraGrid1_BeforeRowExpanded(object sender, Infragistics.Win.UltraWinGrid.CancelableRowEventArgs e)
    {
        if (this.hasPopulatedChildBand)
            return;

        DataTable dt = ((DataSet)this.ultraGrid1.DataSource).Tables[1];
        dt.Columns.Add("Col 2", typeof(int));
        dt.Columns.Add("Col 3", typeof(decimal));
        dt.Columns.Add("Col 4", typeof(bool));
        dt.Columns.Add("Col 5", typeof(DateTime));

        for (int i = 0; i < 30; i++)
        {
            dt.Rows.Add(new object[] { "Row " + i.ToString(), i, i * 1.234m, i % 2 == 0, DateTime.Now.AddYears(i) });
        }
        this.hasPopulatedChildBand = true;
    }

    Is this roughly the same approach that you described (ignoring how you're getting your data, since that shouldn't be relevant)?  I add a column and the DataRelation at first, but no data, and populate the child band once I try to expand a row.  When I do this, the child data correctly shows up.  If my approach is the same, then you should try to download the latest service release to see if the issue is resolved in your application.

    -Matt

Children