jvwiv Posted May 12, 2008 Report Share Posted May 12, 2008 I have a child grid that I want to add a record to. The parent grid uses a unique key counter field that I need to pass into the child grid during record addition. I'm utilizing the following code to retrieve the ukid... Protected Sub Grid2_ItemInserting(ByVal sender As Object, ByVal e As GridFX.WebForms.GridItemInsertingEventArgs) Dim mod1 As IPQ = New IPQDim seqno As Int16 Dim ukid As Int16ukid = Grid1.SelectedItems(0).DataValues.PrimaryKey.ToString seqno = mod1.GetNextIPQNumber(ukid)e.DataValues.Item("ukid") = ukid e.DataValues.Item( "Sequence") = seqno End SubThe issue is that the ukid is not necessarily related to the grid record I'm working with. If I simply click on the + button to expand the child grid (grid2), the parent record that was used does not become the selected record and the ukid is not from the record that I'm adding. For example, record number 1 is currently selected. Click on the + button of record number 2 to show the children, click on the add button of grid # 2 and add the value. Run thru the code above and you'll see that the ukid is from record number 1, not record # 2. However, if I click on record number 2, then the + button, the selected UKID is that of record #2. How can I get the correct results? Link to comment Share on other sites More sharing options...
StephenP Posted May 22, 2008 Report Share Posted May 22, 2008 Hi, So you need the item from Grid1 that contains the Grid2 object that is inserting data, correct? In that case, replace the "Grid1.SelectedItems(0)" with "((Grid)sender).ParentGridItem" This takes the "sender" parameter, which is the Grid2 that is inserting, and gets its parent item, which is simply Grid.ParentGridItem. That should fix it Thanks! Link to comment Share on other sites More sharing options...
jvwiv Posted May 22, 2008 Author Report Share Posted May 22, 2008 Hi Stephen, Not sure if I'm missing something, but the code doesn't work as intended. ((Grid)sender).datavalues.primarykey.tostring The error I receive is that the ((grid)sender) isn't found. What am I doing wrong? John Link to comment Share on other sites More sharing options...
StephenP Posted May 22, 2008 Report Share Posted May 22, 2008 John, Is that a complier error? The "sender" parameter in the event handler should be a Grid instance. Maybe try doing "dim insertingGrid as Grid = sender". Then call "insertingGrid.ParentGridItem.DataValues.PrimaryKey.ToString()". That should work. Steve Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.