Hi Didie,
Thanks for your reply. I tried the example program you provided and it worked without any problems however I still haven't been able to get my code to work.
I modified the code as follows to provide some feedback on the problem;
Private
Sub
gvFooBars_DataLoaded(sender
As
Object
, e
As
EventArgs)
Handles
gvFooBars.DataLoaded
With
gvFooBars
Debug.Print(
String
.Format(
"{0} - gvFooBars_DataLoaded"
,
Date
.Now.ToString(
"hh:mm:ss"
)))
If
(.Items.ItemCount > 0)
And
(moFooBar
Is
Nothing
)
Then
.SelectedItem = .Items(0)
End
With
End
Sub
Public
Function
Save(
)
As
Boolean
.
.
.
If
bNew
Then
'-- Add the new object to the collections -----------------------------------------------
Debug.Print(
String
.Format(
"{0} - Adding object to collection"
,
Date
.Now.ToString(
"hh:mm:ss"
)))
mcolFooBars.Add(moFooBar)
gcolFooBars.Add(moFooBar)
''-- If the records are grouped then it appears the record is not added to the grid when it
''-- is added to the mcolFooBars collection?
'If gvFooBars.IsGrouping Then
' Dim iFooBarId As Integer = moFooBar.FooBarId
' Call LoadRecords(miScenarioId)
' moFooBar = FooBarBusiness.GetRecord(iFooBarId, True)
'End If
'-- Select the object in the grid -------------------------------------------------------
Dim
item = mcolFooBars.Where(
Function
(f) f.FooBarId = moFooBar.FooBarId).FirstOrDefault
If
(item IsNot
Nothing
)
Then
Debug.Print(
String
.Format(
"{0} - Object located in collection subset"
,
Date
.Now.ToString(
"hh:mm:ss"
)))
With
gvFooBars
For
Each
item
As
FooBarView
In
.Items
If
item.FooBarId = moFooBar.FooBarId
Then
Debug.Print(
String
.Format(
"{0} - Object located in GridView"
,
Date
.Now.ToString(
"hh:mm:ss"
)))
.SelectedItem = item
.ScrollIntoView(item)
Exit
For
End
If
Next
End
With
Else
.
.
.
End
If
.
.
.
End
Function
The attached screens show the results of my testing as follows;
- Screen 1 shows the screen without any grouping but filtered to display a limited number of records.
- Screen 2 shows the screen after saving a new record (the green shading is a style applied to the grid to highlight records that have been add/modified in the current session).
- Screen 3 shows the screen with grouping applied and after saving the 2nd new record.
- Screen 4 shows the screen with the grouping removed (note the 2nd new record is now displayed)
The following is the output from the debug statements;
10:08:34 - Adding object to collection
10:08:34 - gvWells_DataLoaded
10:08:34 - Object located in collection subset
10:08:34 - Object located in GridView
10:10:23 - gvWells_DataLoaded
10:10:38 - Adding object to collection
10:10:38 - Object located in collection subset
10:11:46 - gvWells_DataLoaded
The entries for 10:08:34 show the statements executed from Screen 2 when the 1st object was added.
The entry for 10:10:23 is when the grouping was applied.
The entry for 10:10:38 is when the 2 object was added (but wasn't displayed in the grid).
The entry for 10:11:46 is when the grouping was removed and the record was then displayed.
Any help you can provide on this would be greatly appreciated.
Regards,
Ray