DataGrids and BindingContext

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Celmer

    #1

    DataGrids and BindingContext

    Can someone please help me with my code. I have a datasetX with two tables,
    tableA and tableB in the datasetX. The tables have a DataRelation named
    A_B_Relation. How can I get the BindingManagerB ase to be a Currency Manager
    so that I can get the current position when there is movement in dataGrid1.
    This is my code:

    // set up the binding contexts for Master/Detail grids
    dataGrid1->DataSource = datasetX;
    dataGrid1->DataMember = S"tableA";
    dataGrid2->DataSource = datasetX;
    dataGrid2->DataMember = S"A_B_Relation" ;
    ....
    ....
    // get the current position
    BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX,
    S"tableA"];
    DataRowView* view = __try_cast<Data RowView*>(manag er->Current); // this
    line fails with a Bad Cast exception

    The above code produces a BindingManagerB ase of type PropertyManager , not a
    Currency Manager. How can I get a CurrencyManager that will cast to a
    DataRowView of the current position? Please help.



  • Marcus Heege

    #2
    RE: DataGrids and BindingContext

    Haven't tried it, but since your data source is datasetX, you should use

    BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX];

    instesad of

    BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX, "tableA"];

    HTH
    Marcus Heege


    "John Celmer" wrote:
    [color=blue]
    > Can someone please help me with my code. I have a datasetX with two tables,
    > tableA and tableB in the datasetX. The tables have a DataRelation named
    > A_B_Relation. How can I get the BindingManagerB ase to be a Currency Manager
    > so that I can get the current position when there is movement in dataGrid1.
    > This is my code:
    >
    > // set up the binding contexts for Master/Detail grids
    > dataGrid1->DataSource = datasetX;
    > dataGrid1->DataMember = S"tableA";
    > dataGrid2->DataSource = datasetX;
    > dataGrid2->DataMember = S"A_B_Relation" ;
    > ....
    > ....
    > // get the current position
    > BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX,
    > S"tableA"];
    > DataRowView* view = __try_cast<Data RowView*>(manag er->Current); // this
    > line fails with a Bad Cast exception
    >
    > The above code produces a BindingManagerB ase of type PropertyManager , not a
    > Currency Manager. How can I get a CurrencyManager that will cast to a
    > DataRowView of the current position? Please help.
    >
    >
    >
    >[/color]

    Comment

    • John Celmer

      #3
      Re: DataGrids and BindingContext

      Thanks. Your advice led to a resolution. And as I also later needed a
      DataRowView, I changed my source from a dataset to a dataview. Thanks
      again.

      "Marcus Heege" <Marcus Heege@discussio ns.microsoft.co m> wrote in message
      news:3061C333-B48A-46CD-B46A-F6EB6E4F0498@mi crosoft.com...[color=blue]
      > Haven't tried it, but since your data source is datasetX, you should use
      >
      > BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX];
      >
      > instesad of
      >
      > BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX,
      > "tableA"];
      >
      > HTH
      > Marcus Heege
      >
      >
      > "John Celmer" wrote:
      >[color=green]
      >> Can someone please help me with my code. I have a datasetX with two
      >> tables,
      >> tableA and tableB in the datasetX. The tables have a DataRelation named
      >> A_B_Relation. How can I get the BindingManagerB ase to be a Currency
      >> Manager
      >> so that I can get the current position when there is movement in
      >> dataGrid1.
      >> This is my code:
      >>
      >> // set up the binding contexts for Master/Detail grids
      >> dataGrid1->DataSource = datasetX;
      >> dataGrid1->DataMember = S"tableA";
      >> dataGrid2->DataSource = datasetX;
      >> dataGrid2->DataMember = S"A_B_Relation" ;
      >> ....
      >> ....
      >> // get the current position
      >> BindingManagerB ase* manager = Form1::BindingC ontext->Item[datasetX,
      >> S"tableA"];
      >> DataRowView* view = __try_cast<Data RowView*>(manag er->Current); // this
      >> line fails with a Bad Cast exception
      >>
      >> The above code produces a BindingManagerB ase of type PropertyManager , not
      >> a
      >> Currency Manager. How can I get a CurrencyManager that will cast to a
      >> DataRowView of the current position? Please help.
      >>
      >>
      >>
      >>[/color][/color]


      Comment

      Working...