User Controls with Delegates and Listeners

G

Guest

Hi

I am creating a UserControl that is a Grid containing a DataTable
The user will have the ability to create 1-n of these controls that display
different dataTables but they are all related with a key

T1 = Customer Name
T2= Customer Address
T3 = Customer Phone number

As These UserControls are added I'd like the grids to know about each other
and react so As you move to a new row in one table they all update to the
correct matching row. I was thinking of doing this thru delgates but wasn't
sure how to
1)Pass the delegate info to each other child to setup Listener as new child is
created
2)As I add new grid how to have the new child add a listener for existing
children and any new children added

Any suggestions would be appreciated
Thanks
 
S

Simon Tamman

Sounds like a job for the BindingSource object (.NET 2.00) you can chain
BindingSources so that the "Current" row on the main binding source being
changed will update all the chained BindingSources to display the
information for the new row.

HTH

Simon
 
L

Linda Liu [MSFT]

Hi,

Based on my understanding, you have several data tables which are related
with a key, e.g. CustomerID and you bind a DataGridView control to each
data table. When you change the current row in one data table, you'd like
to update other data tables to the correct matching row. If I'm off base,
please feel free to let me know.

I don't think we need to use delegate in this scenario. We could use
BindingSource in this practice. You may add a BindingSource component for
each data table in your project. Set each BindingSource's DataSource and
DataMember properties to the dataset and the corresponding data table, and
then bind the corresponding DataGridView to the BindingSource component.

When the current row in a DataGridView is changed, you may find the value
of the key column of the current row as follows.

object keyvalue = (this.bindingSource1.Current as
DataRowView)["CustomerID"];

You may then find the matching row in other BindingSource components and
set the current row to the matching row as follows.

int index = this.bindingSource2.Find("CustomerID", keyvalue);
this.bindingSource2.Position = index;

Hope this helps.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top