Re: reflect changes in data bound control when underlying data table changes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • \Ji Zhou [MSFT]\

    Re: reflect changes in data bound control when underlying data table changes

    Hello Ashutosh,

    I see your points. As to your two new concerns, I am give the detailed
    comments in the following.

    1. Is it possible to achieve this result without calling Update on the
    route table? I want to give the user an option to save/reject the changes.

    Yes, we can achieve the objective without calling the Update function on
    the route table. The necessary thing we need to do is updating the
    dummy_docks. Of course we can fill the dummy_docks from the local
    routeDataGrid, so that we do not need to save changes to data base
    immediately. If we are using .NET 3.0 or above version Framework, we can
    adopt the LINQ to achieve that easily as follows.

    System.Collecti ons.Generic.IEn umerable<Int32d dE;

    private void Form1_Load(obje ct sender, EventArgs e)
    {
    this.lanesTable Adapter.Fill(th is.testDataSet. lanes);
    this.routeTable Adapter.Fill(th is.testDataSet. route);

    ddE = (from d in this.testDataSe t.route
    orderby d.dock
    select d.dock).Distinc t();

    foreach (Int32 d in ddE)
    {
    this.testDataSe t.dummy_docks.R ows.Add(new object[] { d });
    }

    this.routeDataG ridView.RowsAdd ed += new
    DataGridViewRow sAddedEventHand ler(routeDataGr idView_RowsAdde d);

    this.dataGridVi ewComboBox1.Dat aSource = this.testDataSe t.dummy_docks;
    this.dataGridVi ewComboBox1.Dis playMember = "dock";

    this.dataGridVi ewComboBox2.Dat aSource = this.testDataSe t.dummy_docks;
    this.dataGridVi ewComboBox2.Dis playMember = "dock";

    this.dataGridVi ewComboBox3.Dat aSource = this.testDataSe t.dummy_docks;
    this.dataGridVi ewComboBox3.Dis playMember = "dock";

    this.dataGridVi ewComboBox4.Dat aSource = this.testDataSe t.dummy_docks;
    this.dataGridVi ewComboBox4.Dis playMember = "dock";

    this.dataGridVi ewComboBox5.Dat aSource = this.testDataSe t.dummy_docks;
    this.dataGridVi ewComboBox5.Dis playMember = "dock";
    }

    void routeDataGridVi ew_RowsAdded(ob ject sender,
    DataGridViewRow sAddedEventArgs e)
    {
    this.testDataSe t.dummy_docks.C lear();
    ddE = (from d in this.testDataSe t.route
    orderby d.dock
    select d.dock).Distinc t();

    foreach (Int32 d in ddE)
    {
    this.testDataSe t.dummy_docks.R ows.Add(new object[] { d });
    }
    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    this.testDataSe t.route.Rows.Ad d(new object[] {"r7", 4 });
    }

    Whenever an Row is added into the routeDataGrid, the RowAdded event fires
    and we fill the dummy_docks from there. If we cannot use the LINQ, we have
    to iterate through the routeDataGrid and pick up all distinct dock value by
    our own codes, and then fill the dummy_docks. That means some workload.

    2.I agree with your comment. If we do not want to update the local data to
    the data base, we have to manipulate it on local side. The LINQ feature
    will release our efforts from traversing all items for it supports querying
    the memory data objects, like Array, List and DataTable. Would you like to
    considering adopt the LINQ in your project? We can find some getting start
    articles in the following articles,





    Please let me know if you need any future assistance. I will be glad to be
    of help. Have a nice day!


    Best regards,
    Ji Zhou
    Microsoft Online Community Support

    =============== =============== =============== ====
    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    msdnmg@microsof t.com.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    =============== =============== =============== ====

Working...