473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Synchronizing 2 grids via the CurrencyManager

I have written a custom databound grid control that we've been using
successfully for months, but one of our developers has just run into a
problem that I can't figure out.

The code for setting it up is as follows:

DataSet dataSet = new DataSet( "TestSet" );

DataTable tableParent = dataSet.Tables.Add( "TableParent" );
tableParent.Columns.Add( "ID", typeof( Int32 ) );
tableParent.Columns[ "ID" ].AutoIncrement = true;
tableParent.Columns[ "ID" ].Unique = true;
tableParent.Columns.Add( "Col1", typeof(Int32) );
tableParent.Columns.Add( "Col2", typeof(Int32) );

DataTable tableChild = dataSet.Tables.Add( "TableChild" );
tableChild.Columns.Add( "ID", typeof( Int32 ) );
tableChild.Columns.Add( "Col1", typeof(Int32) );
tableChild.Columns.Add( "Col2", typeof(Int32) );

dataSet.Relations.Add( "Child2Parent", tableParent.Columns[ "ID" ],
tableChild.Columns[ "ID" ] ).Nested = true;

gridParent.DataSource = dataSet;
gridParent.DataMember = "TableParent";
gridChild.DataSource = dataSet;
gridChild.DataMember = "TableParent.Child2Parent";

The way it is supposed to work (and does work with the MS DataGrid) is that
when you select a row in the parent table, it should set the data in the
child table to all children of the selected parent.

In my grid, when the current cell changes, I set the position in the
CurrencyManager to the new position. My understanding (and apparently a
false one) was that the CurrencyManager would update the position in the
underlying dataset which in turn would then inform all CurrencyManagers
bound to it. Apparently that's not the case.

The parent grid receives the CurrencyManager.PositionChanged event but the
child grid receives no events from its CurrencyManager.

How am I supposed to propagate an update to the child grid?

Thanks.

Pete
Nov 16 '05 #1
1 2037
Okay, after digging through DataGrid, BindingContext, CurrencyManager and
RelatedCurrencyManager, I have a much better idea of how it's supposed to
operate, but I still haven't solved the problem.

Both the parent and child grids are getting RelatedCurrencyManager objects
from the BindingContext because they both have DataMember set, and as far as
I can tell, this is correct. The parent grid's RelatedCurrencyManager is the
parent of the child grid's RelatedCurrencyManager.

The child RelatedCurrencyManager is subscribing to the CurrentChanged of the
parent. Now, I know the parent CurrentChanged is getting called, because I
subscribe to it in my grid.

In RelatedCurrencyManager.ParentManager_CurrentChange d, a call is made to
this.SetDataSource() which should trigger calls to ItemChanged and
PositionChanged in the child grid's RelatedCurrencyManager, which the child
grid subscribes to, but these aren't getting called.

I'm just stumped.

Pete
"Pete Davis" <pd******@NOSPAM.hotmail.com> wrote in message
news:e-********************@giganews.com...
I have written a custom databound grid control that we've been using
successfully for months, but one of our developers has just run into a
problem that I can't figure out.

The code for setting it up is as follows:

DataSet dataSet = new DataSet( "TestSet" );

DataTable tableParent = dataSet.Tables.Add( "TableParent" );
tableParent.Columns.Add( "ID", typeof( Int32 ) );
tableParent.Columns[ "ID" ].AutoIncrement = true;
tableParent.Columns[ "ID" ].Unique = true;
tableParent.Columns.Add( "Col1", typeof(Int32) );
tableParent.Columns.Add( "Col2", typeof(Int32) );

DataTable tableChild = dataSet.Tables.Add( "TableChild" );
tableChild.Columns.Add( "ID", typeof( Int32 ) );
tableChild.Columns.Add( "Col1", typeof(Int32) );
tableChild.Columns.Add( "Col2", typeof(Int32) );

dataSet.Relations.Add( "Child2Parent", tableParent.Columns[ "ID" ],
tableChild.Columns[ "ID" ] ).Nested = true;

gridParent.DataSource = dataSet;
gridParent.DataMember = "TableParent";
gridChild.DataSource = dataSet;
gridChild.DataMember = "TableParent.Child2Parent";

The way it is supposed to work (and does work with the MS DataGrid) is that when you select a row in the parent table, it should set the data in the
child table to all children of the selected parent.

In my grid, when the current cell changes, I set the position in the
CurrencyManager to the new position. My understanding (and apparently a
false one) was that the CurrencyManager would update the position in the
underlying dataset which in turn would then inform all CurrencyManagers
bound to it. Apparently that's not the case.

The parent grid receives the CurrencyManager.PositionChanged event but the
child grid receives no events from its CurrencyManager.

How am I supposed to propagate an update to the child grid?

Thanks.

Pete

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Keith Veleba | last post by:
Hello to all fellow c.l.p'ers! Long-time listener, first-time caller. Background: I'm working on a project where I have to do some serious multithreading. I've worked up a decorator in Python...
0
by: Bamse | last post by:
Hi, I want to synchronize (the Master-Details concept) 2 grids in 2 different forms by using BindingContext. is this possible?
1
by: Kevin | last post by:
Hi Al When I have a text box, list box, and a datagrid, how does a CurrencyManager relate to all these controls(seeing as though the datagrid uses Complex binding and textbox and list box use...
4
by: Kris Bethea via DotNetMonster.com | last post by:
Greetings, I have a VB.NET program that I am trying to convert to C# (my office decided that we are going to use C# from now on). I've only been working with C# for about a month now, so this...
2
by: orekinbck | last post by:
Hi There Using C# forms, I have a main screen that contains 2 data grids. * The data grids are connected to ArrayLists (each grid has its own ArrayList) * The data grids are intended for...
10
by: D | last post by:
hi I have a form with 2 datagrids showing related table data in a master / child or order / order details type relationship. I would like to auto select the row in the order details table which...
2
by: Christopher D. Wiederspan | last post by:
We are getting ready to move an ASP.NET application off of a single development machine and onto a "webfarm". Basically our webfarm is a bunch of identical servers with the load-balancing provided...
4
by: Richard Fagen | last post by:
Hi, I wondering if someone can explain the best way to show three datagrids in a parent/child/grandchild relationship? For example: Take a simple form with 3 datagrids - the top for the...
3
by: Brian Richardson | last post by:
Hi, Please can anyone kindly offer some suggestions as to why the CurrencyManager might not refresh. I am using the CurrencyManager to navigate through a DataView. I am aware that there is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.