For a better grip you can do all the things manually. For example you can
utilize the Parent DataGridView's SelectionChanged event. In the handler of
this event you can clear your child DataGridView's content and then refill
it with new "related" content.
Another approach is that you can directly bind the child DataGridView with
the relation key. Here is how this happens,
1) You have a Typed DataSet in which there are 2 tables (parent, child) both
have already been linked in DataSet
2) Now on your Form add that DataSet
3) Add a BindingSource (for Parent Table binding)
4) Bind that BindingSource with DataSet's Parent Table
5) Add another BindingSource (for Child Table binding)
6) Bind the new BindingSource with the Parent BindingSource like that
ChildTableBindingSource.DataSource = ParentTableBindingSource
ChildTableBindingSource.DataMember = FK_ParentTable_ChildTable
Note that "FK_ParentTable_ChildTable". This is the relation which you have
created in your DataSet
7) Now you just have to bind your DataGridViews with these BindingSources
8) Obviously Parent DataGridView should be bind to ParentTableBindingSource
9) While Child DataGridView should be bind to ChildTableBindingSource
Note that your DataSet's Parent and Child Tables must have all the data.
Which means child table will contain all the children of all the parents.
Therefore this approach is NOT recommended for larger data.
On Thu, Sep 30, 2010 at 6:55 PM, Dwight Shackelford <
[email protected]> wrote:
> Thanks. I'm doing a windows app, so its a datagridview. I was just using
> shorthand without knowing I was causing a problem. I'll look at what you
> advised.
>
>
> On Thu, Sep 30, 2010 at 1:22 AM, Cerebrus <[email protected]> wrote:
>
>> I think what you are referring to is actually a Master-Details
>> scenario. Also, you keep confusing the matter by calling the control a
>> Datagrid sometimes and a Datagridview sometimes. Note that the former
>> could be either a Windows control or a Web control and the latter is a
>> Windows forms control. So, at this time, it is unclear if you are
>> creating a Windows app or Web app.
>>
>> Whatever it is, I think the first step is to create DataRelations
>> between the relevant tables in the Dataset. Then you could get related
>> records via the GetChildRows() method and bind the second control to
>> that array.
>>
>> On Sep 30, 3:10 am, Dwight Shackelford <[email protected]>
>> wrote:
>> > So, nobody has any pointers on how to link two datagridviews? I've
>> already
>> > linked the tables in the dataset. Nothing happens when I click on the
>> > parent datagridview.
>> >
>> > On Wed, Sep 29, 2010 at 10:18 AM, Dwight Shackelford <
>> >
>> >
>> >
>> > [email protected]> wrote:
>> > > Nah, unless I"m missing something, those didn't help. I'm already
>> familiar
>> > > with relational design. I want to know how to link the content
>> (filter) of
>> > > one datagrid to the selected row in another datagrid. If that is in
>> these
>> > > links, it's not popping out at me.
>> >
>> > > On Wed, Sep 29, 2010 at 6:56 AM, Dwight Shackelford <
>> > > [email protected]> wrote:
>> >
>> > >> I'll look at this. I do have a primary key/foreign key link set up
>> in the
>> > >> DataSet. It's not working automatically. Google didn't really give
>> me much
>> > >> in the first couple of pages.
>> >
>>
>
>