By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Collections.Generic.IEnumerable<Int32ddE;

private void Form1_Load(object sender, EventArgs e)
{
this.lanesTableAdapter.Fill(this.testDataSet.lanes );
this.routeTableAdapter.Fill(this.testDataSet.route );

ddE = (from d in this.testDataSet.route
orderby d.dock
select d.dock).Distinct();

foreach (Int32 d in ddE)
{
this.testDataSet.dummy_docks.Rows.Add(new object[] { d });
}

this.routeDataGridView.RowsAdded += new
DataGridViewRowsAddedEventHandler(routeDataGridVie w_RowsAdded);

this.dataGridViewComboBox1.DataSource = this.testDataSet.dummy_docks;
this.dataGridViewComboBox1.DisplayMember = "dock";

this.dataGridViewComboBox2.DataSource = this.testDataSet.dummy_docks;
this.dataGridViewComboBox2.DisplayMember = "dock";

this.dataGridViewComboBox3.DataSource = this.testDataSet.dummy_docks;
this.dataGridViewComboBox3.DisplayMember = "dock";

this.dataGridViewComboBox4.DataSource = this.testDataSet.dummy_docks;
this.dataGridViewComboBox4.DisplayMember = "dock";

this.dataGridViewComboBox5.DataSource = this.testDataSet.dummy_docks;
this.dataGridViewComboBox5.DisplayMember = "dock";
}

void routeDataGridView_RowsAdded(object sender,
DataGridViewRowsAddedEventArgs e)
{
this.testDataSet.dummy_docks.Clear();
ddE = (from d in this.testDataSet.route
orderby d.dock
select d.dock).Distinct();

foreach (Int32 d in ddE)
{
this.testDataSet.dummy_docks.Rows.Add(new object[] { d });
}
}

private void button1_Click(object sender, EventArgs e)
{
this.testDataSet.route.Rows.Add(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,

http://www.codeproject.com/KB/vista/LINQ_1.aspx
http://www.codeproject.com/KB/vista/LINQ2.aspx
http://www.codeproject.com/KB/vista/LINQ_3.aspx

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:
ms****@microsoft.com.

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

Nov 7 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.