listchanged event of child table´s dataview?

I have a dataset with two tables. One is called "Article" and the other "ArticlePlan".
"Article" is the master table and "ArticlePlan" the child table.

Then I created two seperate dataviews for the dataset tables as follows:
viewArticle = dsArticleArticlePlan.Article.defaultview
viewArticlePlan = dsArticleArticlePlan.ArticlePlan.defaultview

Next I bind a datagrid to the master table´s default view like this:
datagrid.datasource = viewArticle

Next I add handlers for the listchanged event for both dataviews seperately.

Now when clicking on the column header of the datagrid(sorting) the listchanged event gets fired properly ONLY if I´m in the Master Table.
When switching to the child table and clicking on the datagrid column header the listchanged event for the child table´s dataview does not fire.

Does anyone know what may be wrong


Answer this question

listchanged event of child table´s dataview?

  • CoverPpl

    There are a couple issues here: one is that you're _not_ looking at the DefaultView for the child table, you're looking at a new filtered version.  To work around this, you could hook up the handler for the list that matches your child table.  In the code below, the grid's bound to Table[0] of dataSet11, and I might navigate to the CustomersOrders relation.  (If the grid were bound to the dataset directly, I'd use BindingContext[dataSet11, "FirstTableName.RelationName"] instead.

    The second thing is that even that's not good enough: whenever you move to a different child record, a new DataView may be created (it stores the ones that you've already been to).  That means you'd want to hook up the ListChanged event whenever you navigate to a child (you should remove the handler first -- that way, you won't get a bunch of handlers if you keep going back to the children of the same list).

    -Scott


    private void Form1_Load(object sender, System.EventArgs e)
    {
      dataGrid1.Navigate += new NavigateEventHandler(HookChildViewChanged);
    }

    void HookChildViewChanged(object o,NavigateEventArgs e)
    {
      if (e.Forward) 
      {
        DataView dv = (DataView)(((CurrencyManager)BindingContext[dataSet11.Tables[0], "CustomersOrders"]).List);
        //Remove the handler, in case you already have one
        dv.ListChanged -= new ListChangedEventHandler(dv_ListChanged);
        dv.ListChanged += new ListChangedEventHandler(dv_ListChanged);
      }
    }

    private void dv_ListChanged(object sender, ListChangedEventArgs e)
    {
      //The list has changed
    }

  • listchanged event of child table´s dataview?