PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Insert ForeignKey of parent DataGrid in child

Reply

Insert ForeignKey of parent DataGrid in child

 
Thread Tools Rate Thread
Old 29-11-2005, 04:41 PM   #1
Sebastian-Hiller@gmx.de
Guest
 
Posts: n/a
Default Insert ForeignKey of parent DataGrid in child


Hi,

I have two dataGrids bound to two different datasets, which relate to
each other as parent/child. The primary key/foreign key columns are
hidden in the DataGrid. If I select a Parent the corresponding
child's are displayed.
I want to add a row to the child, with the currently selected parents
primary key as foreign key. How can I insert the right foreign key? I
tried the DataTable "RowChanging" and "RowChanged" event, but I got a
NOT-NULL violation from the DataGrid. I tried to use a DefaultValue and
then changed this DefaultValue within the RowChanging-Event, that
caused an error ("Can't change default value in RowChanging
event.").

I miss a "NewRow" event in DataGrid or something like that, so that I
can simply edit the new row and insert the proper foreign key.

My current solution is to catch the OnMouseUp Event on Parent DataGrid
and set child Foreign key column Default Value to the selected parent
Primary Key value. But this is more a hack then a Solution:

private void dataGridBenchmark_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
dataSetBenchmarks1.BenchmarkVersion.Benchmarkprogramm_IDColumn.DefaultValue=dataSetBenchmarks1.Benchmarkprogramm[dataGridBenchmark.CurrentRowIndex].Benchmarkprogramm_ID;
}

The problem is, that the user has to click the parent and can't use
the keyboard.

Any ideas? Thanks!

  Reply With Quote
Old 29-11-2005, 05:22 PM   #2
Sebastian-Hiller@gmx.de
Guest
 
Posts: n/a
Default Re: Insert ForeignKey of parent DataGrid in child

Hi again,

turns out I did a mistake in my code. I assigned the wrong column in a
relationship. After I corrected the relationship every thing runs
smooth, the foreign keys in the child DataGrid are automatically set to
the selected Parent Primary Key, then inserting a new row.

I have to apologize.

Best regards.
Sebastian

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off