none
[DataTable] Position changed on Input RRS feed

  • Question

  • Relation:

    There tree DataTable's in parent-child-relation.

     

    Table1
    +--> Table2
    +-->Table3

     

    In Table2 is an Expression Column, that summeries an field from Table3.

    That works very well.

     

    But why moves the "Position", when I change the field in Table3. After I cleared all DataRow's and reloaded them?

    I suggest, that some goes wrong with the internal Indexes, because in the method "DataTable.RecordChanged" the two arrays are unequal in there length.

     

     

    Please ask when something is unclear. It is hard to explain.

     

    I have also and small example project.

    • Moved by SamAgain Tuesday, June 8, 2010 2:40 AM better fit (From:.NET Base Class Library)
    Monday, June 7, 2010 11:29 PM

All replies

  • In Table2 is an Expression Column, that summeries an field from Table3.

    But why moves the "Position", when I change the field in Table3. After I cleared all DataRow's and reloaded them?


    Hi Neolithos,

    I am not clear about what do you mean by the above sentences ? What are you going to accomplish ? Could you please explain a little more and provide some sample code about the example project ? Thanks.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 9, 2010 8:29 AM
    Moderator
  • Hi Alex,

    Binding:

     

      bsTable1.DataSource = ds;
      bsTable1.DataMember = "DataTable1";
      bsTable2.DataSource = bsTable1;
      bsTable2.DataMember = "FK_DataTable1_DataTable2";
      bsTable3.DataSource = bsTable2;
      bsTable3.DataMember = "FK_DataTable2_DataTable3";
    
      label1.DataBindings.Add("Text", bsTable1, "Name", true);
      textBox1.DataBindings.Add("Text", bsTable3, "Number", true, DataSourceUpdateMode.OnPropertyChanged, DBNull.Value, null, null);
    

     

    1. Step:

    I insert in the DataSet:

     

      ds.Tables["DataTable1"].Rows.Add(1, "Test1");
    
      ds.Tables["DataTable2"].Rows.Add(1, 1);
      ds.Tables["DataTable2"].Rows.Add(2, 1);
      ds.Tables["DataTable2"].Rows.Add(3, 1);
    
      ds.Tables["DataTable3"].Rows.Add(1, 1);
      ds.Tables["DataTable3"].Rows.Add(2, 2);
      ds.Tables["DataTable3"].Rows.Add(3, 3);
    

     

    2. Step:

    I clear the data and insert data again:

     

      ds.Tables[2].Clear();
      ds.Tables[1].Clear();
      ds.Tables[0].Clear();
    
      ds.Tables[0].Rows.Add(2, "Test2");
    
      ds.Tables[1].Rows.Add(4, 2);
      ds.Tables[1].Rows.Add(5, 2);
      ds.Tables[1].Rows.Add(6, 2);
    
      ds.Tables[2].Rows.Add(1, 4);
      ds.Tables[2].Rows.Add(2, 5);
      ds.Tables[2].Rows.Add(3, 6);
    

     

    3. Step:

    I change in textbox1 the value.

    And know the Position of bsTable2 changes to Position+1.

    Questions?

     

    best regards,

    Matthias

    • Edited by Neolithos Wednesday, June 9, 2010 9:43 AM Orthographie
    Wednesday, June 9, 2010 9:41 AM
  • I change in textbox1 the value.

    And know the Position of bsTable2 changes to Position+1.

    Hi Matthias,

    How did you change the textbox1's value and changed it to what ? Did you want to know why the Position of bsTable2 changes to Position+1 ? Or else ? What are you going to accomplish with this code ? Sorry, I still do not understand your meaning.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, June 9, 2010 11:01 AM
    Moderator
  • How did you change the textbox1's value and changed it to what?
    I change the value by keyboard. For expample to "12" or some other number.
    Did you want to know why the Position of bsTable2 changes to Position+1? Or else?
    Correct. Why is the position changing, that could not normal? And how I can prevent the DataTable from doing that.
    What are you going to accomplish with this code ?
    This is a small example of a problem, what I have in an larger application: It is not nice, when you change some value, and as an result the current record position is changing to another. That is an bug! And I have know idea, what is going wrong.
    Wednesday, June 9, 2010 12:39 PM
  •   bsTable1.DataSource = ds;

      bsTable1.DataMember = "DataTable1";

      bsTable2.DataSource = bsTable1;

      bsTable2.DataMember = "FK_DataTable1_DataTable2";

      bsTable3.DataSource = bsTable2;

      bsTable3.DataMember = "FK_DataTable2_DataTable3";



      label1.DataBindings.Add("Text", bsTable1, "Name", true);

      textBox1.DataBindings.Add("Text", bsTable3, "Number", true, DataSourceUpdateMode.OnPropertyChanged, DBNull.Value, null, null);


    Hi Matthias,

    When you bind the bindingsources like the above code (bind the data relations between the data sources) and change the record of one bindingsource, the record of the other bindingsouce may also been changed accordingly. This is due to the parent - child relationship of the data sources. One example for that is we sometimes need to use only one BindingNavigator to navigate two related bindingsources, we can implement it by binding the datarelation between the two data sources to the bindingsource. If you have ever used typed dataset(with parent-child datatables)created by designer, and drag and drop the parent-child datatables from the data source window to the form to generate datagridviews, in the code which is auto-created, you will find something like the code you provide.

    this.relationFK_Orders_Customers = new global::System.Data.DataRelation("FK_Orders_Customers", new global::System.Data.DataColumn[] {
                this.tableCustomers.CustomerIDColumn}, new global::System.Data.DataColumn[] {
                this.tableOrders.CustomerIDColumn}, false);
    this.Relations.Add(this.relationFK_Orders_Customers);

    this.ordersBindingSource.DataMember = "FK_Orders_Customers";
    this.ordersBindingSource.DataSource = this.customersBindingSource;

    And then if you navigate through one bindingsouce(parent), record in other bindingsource(child) will changed accordingly. If you do not want that behaviour, then do not bind the bindingsources with datarelations of the data sources.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, June 10, 2010 6:32 AM
    Moderator
  • Hi Alex,

     

    thanks for this long and good answer.

     

    But the trouble is, that the user did not change the parent record position. It is the DataTable that changes the record position.

    The example should make that clear:

    http://wh12.tu-dresden.de/~neolitho/Download/BindingTest.zip

     

    Matthias
    Thursday, June 10, 2010 9:41 AM