Hi,
I have 2 tables(tableA, tableB) having parent/ child relationship (Rel_tableA_tableB).
2 BindingSources.
bsA.DataSource = tableA
bsB.Datamember=Rel_tableA_tableB
bsB.DataSource=bsA
I have ultragrid having Datasource as bsA, due to relationship my grid shows 2 bands. I am trying to add a row in child band and setting default values for the columns by using the add button provided within grid.
the code is like this
Try If e.Row.Band.Index = 0 Then '...add default data for parent row else lobjDrv = CType(bsB.Current, DataRowView)With lobjDrv 'defaults when a new detail is added .Item("Date_Update") = Now 'there are more cols as well bsB.EndEdit() End With End IfCatch ex As Exception Throw End Try
Try
If e.Row.Band.Index = 0 Then
'...add default data for parent row
else
lobjDrv = CType(bsB.Current, DataRowView)With lobjDrv 'defaults when a new detail is added .Item("Date_Update") = Now 'there are more cols as well bsB.EndEdit() End With
lobjDrv = CType(bsB.Current, DataRowView)
'defaults when a new detail is added
.Item("Date_Update") = Now 'there are more cols as well bsB.EndEdit()
bsB.EndEdit()
End With
End If
Throw
End Try
'********************************************
End Sub
lobjDrv = CType(bsB.Current, DataRowView)....doesn't point to newly added row....it points to first row in the child band and whatever default we added goes to first row in the grid.
is this a known bug? Ultragrid version is 7.1.20071.1055.
Thanks in advance
I'm not really sure how the BindingSource could possibly be correct in this case, actually, or that the Current property of a child BindingSource has any real meaning here. The grid does not deal with the BindingSource, it deals with the CurrencyManager, and there is one CurrencyManager for each island of data. That means that there is a separate "Current" row under each parent row, not just one current row on the whole band.
Hi Mike,
Thanks for the reply, as a workaround I am already using e.Row.ListObject , but my question is why bsB.current is not pointing to the newly added row. If you add a row to band 0 (parent), bsA will correctly point to the new row. why the behavior is different for parent and child band.
I was using the add buttons provided within grid.
Thanks
I'm not sure about the position. I suspect it's not a bug.
But in any case you can use e.Row.ListObject instead of bsb.Current to get the DataRowView that corresponds to the newly-added row.