PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert ForeignKey of parent DataGrid in child
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert ForeignKey of parent DataGrid in child
![]() |
Insert ForeignKey of parent DataGrid in child |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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! |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

