I''m having a wierd problem trying to set the current row in a master-detail pair of grids after an update. Here''s what I''m doing:
When calling the "Save" button on my form, the first thing I do is get the current position of the master (and detail) grids using the Currency Manager and assigning mastIndex = cm.Position() and repeating for the detail grid with detailIndex.
An example would be a three row master grid :
ROW1
ROW2
ROW3
and assume there are three rows for each of these master rows:
ROW1A
ROW1B
ROW1C, etc.
If I''m sitting on master, ROW2, the masterIndex value is 1 and the detailIndex is 0. When the update completes, I refresh both grids with:
DataGrid1.Refresh()
DataGrid2.Refresh()
If mastIndex > 0 and mastIndex < DataGrid1.Model.RowCount Then
DataGrid1.ScrollCellInView(mastIndex,1)
DataGrid1.CurrentCell.MoveTo(mastIndex,1)
End If
MsgBox("Saved")
The current master row always jumps to the first one in the dataset. I really need to be able to keep current row positions for both grids because the end users can sometimes have lots of data in each and to scroll back to where they where is not good.
I''ve even tried a DataGrid1.Select() after the MsgBox to ensure the master grid is selected.
Your quick attention is most appreciated! Thanks again.
HS
Helmut Scheiss
June 15, 2005 04:59 AM UTC
After playing around I''ve found that the following code is repositioning the master grid position:
DataGrid1.CurrentCell.MoveTo(mastIndex+1,0)
DataGrid1.CurrentCell.ScrollInView(0)
DataGrid1.Refresh()
DataGrid2.Refresh()
However, if I was on master row #2 before the update, when the update completes, it''s still back on master row #2, but all of the related details records display for the first master in the set, ie. all of Row1''s detail is displayed.
Is something off on my timing?
AD
Administrator
Syncfusion Team
June 15, 2005 08:54 AM UTC
Do things work right change the details as you click around the master grid? If so, you might try calling currencymanager.Refresh on the details currencymanager.
HS
Helmut Scheiss
June 15, 2005 01:12 PM UTC
Yes, the detail grid does change correctly as you click the master grid rows. It''s only after the update completes where the detail grid "resets" and displays records for the 1st row of the master grid. Clicking on any record within the master grid resumes normal behavior and the proper detail records then appear.
>Do things work right change the details as you click around the master grid? If so, you might try calling currencymanager.Refresh on the details currencymanager.
>
>
AD
Administrator
Syncfusion Team
June 15, 2005 01:56 PM UTC
Did you try calling currencymanager.Refresh on the details currencymanager?
HS
Helmut Scheiss
June 15, 2005 03:39 PM UTC
Yes, I just did and I get the same results. I looked at one of your samples where there are 4 databound grids on the screen and noticed that you are turning the cm off and forcing it to use the Ilist or something like that. What does this do?
>Did you try calling currencymanager.Refresh on the details currencymanager?
>
>
AD
Administrator
Syncfusion Team
June 15, 2005 04:20 PM UTC
I am not sure what sample you are referring to. Where did you see it?
What version of our libraries are you using? You should try 3.2.1.0 if you are not using that version.
If you can upload a sample project showing the problem, maybe we can suggest a solution.
HS
Helmut Scheiss
June 15, 2005 04:36 PM UTC
I''ve uploaded the code being performed in the update subroutine. I''m sure you may have some questions about it. By the way, I am using v3.2.1.0
>I am not sure what sample you are referring to. Where did you see it?
>
>What version of our libraries are you using? You should try 3.2.1.0 if you are not using that version.
>
>If you can upload a sample project showing the problem, maybe we can suggest a solution.
updatesample_2762.zip
AD
Administrator
Syncfusion Team
June 15, 2005 06:04 PM UTC
Just something to try. At the start, call BeginUpdate on both grids. Then set the DataSource on both grids to Nothing and teh DisplayMember on both grids to the empty string. Then do your updating. Then reset the datsources/displaymemebrs on both grids, and call Endupdate on both grids, followed by Refresh on both grids.
HS
Helmut Scheiss
June 16, 2005 04:33 AM UTC
I got it to work with the code I posted earlier, but set both grid''s UseListChangedEvent to false. Is this going to cause a problem later on?
Thanks for your quick help with this nagging problem!
>Just something to try. At the start, call BeginUpdate on both grids. Then set the DataSource on both grids to Nothing and teh DisplayMember on both grids to the empty string. Then do your updating. Then reset the datsources/displaymemebrs on both grids, and call Endupdate on both grids, followed by Refresh on both grids.
AD
Administrator
Syncfusion Team
June 16, 2005 08:09 AM UTC
The UseListChangedEvent is an optimization setting. If things work now with this setting, they should continue to work for you in the future.