S
Sebastian-Hiller
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!
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!