RemoveAt Revisited |
Post Reply |
Author | |
Gutauckis
Newbie Joined: 06 December 2004 Status: Offline Points: 12 |
Post Options
Thanks(0)
Posted: 30 April 2006 at 8:15pm |
While I have searched the forums and found a few others having the same problem as I, there does not seem to be an answer.
I am trying to delete a set of rows and no matter what I do, it never deletes the last row I remove. Yes I "repopulate" still no luck. So if anyone can answer me I would appreciate it. Let's say I have three rows I want to remove, row.index = 12, row.index = 14 and row.index = 16 I use: ReportControl.Records.RemoveAt(12) ReportControl.Records.RemoveAt(14) ReportControl.Records.RemoveAt(16) ReportControl.Populate() and row 16 is still there So what am I doing wrong? |
|
Gutauckis
Newbie Joined: 06 December 2004 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Okay I continue to figure this out so I copy the code from thje sample of RemoveAt: This code when executed removes (deletes) the record after the one selected not the one selected....
Private Sub wndReportControl_KeyDown(KeyCode As Integer, Shift As Integer) On Error Resume Next 'If the delete key is pressed (Delete's keycode = 46) then remove all selected rows If (KeyCode = 46) Then Dim Row As ReportRow 'Enumerate through each selected row in the ReportControls collection of selected rows For Each Row In wndReportControl.SelectedRows 'Removes the selected row, to remove a row you must remove the record attached to the row wndReportControl.Records.RemoveAt (Row.Index) Next 'Any time you add or delete rows(by removing the attached record), you must call the 'Populate method so the ReportControl will display the changes, the rows will remain 'visible until the Populate method is called wndReportCon trol.Populate End If End Sub |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Hi,
In your piece of code: ReportControl.Records.RemoveAt(12) ReportControl.Records.RemoveAt(14) ReportControl.Records.RemoveAt(16) Note that when you remove row 12, the overall number of rows is decresed, and the row which was 14, now becomes 13. To easily get round of this effect, just change the order of operations: ReportControl.Records.RemoveAt(16) ReportControl.Records.RemoveAt(14) ReportControl.Records.RemoveAt(12) -- WBR, Serge |
|
Gutauckis
Newbie Joined: 06 December 2004 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Thanks sserge. I was heading in that direction but assumed that the control only marked the record for deletion but did not delete unitl it was populated again. I reversed my direction as you had suggested and all is good.... I need to stop assuming :) The code I posted for the deleting of a record by pressing the delete key still does not work. I tried a few different ways to get it to work but no luck. Maybe somebody else will figure it out... |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Looks like the problem in the line with RemoveAt. Note that Records and Rows could have different indexes (because of sorting, etc). So far, the corrected line would be:
wndReportControl.Records.RemoveAt (Row.Record.Index) -- WBR, Serge |
|
Waescher
Newbie Joined: 15 September 2006 Location: Germany Status: Offline Points: 27 |
Post Options
Thanks(0)
|
Yes, that did it, great topic!
i really tried to solve that problem in my app without any success! Thank you! |
|
jcollier
Senior Member Joined: 15 February 2006 Status: Offline Points: 250 |
Post Options
Thanks(0)
|
Is there a way to accomplish this using a "For Each"?
Dim row As ReportRow For Each row In rptDrawers.Rows rptDrawers.Records.RemoveAt row.Index Next row rptDrawers.Populate |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
I would not recommend this. Better to use RemoveAll -- WBR, Serge |
|
jcollier
Senior Member Joined: 15 February 2006 Status: Offline Points: 250 |
Post Options
Thanks(0)
|
Actually, I made a mistake in the post.
Change: For Each row In rptDrawers.Rows To: For Each row In rptDrawers.SelectedRows I noticed I made that mistake this morning and changed it but I still have the same problem. |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Anyway, I wouldn't recomment deleting rows in such way, just because of the same reason -- there could be possible a same problem as in the beginning of this topic...
Better to iterate them from the end up to beginning of the collection... -- WBR, Serge |
|
jcollier
Senior Member Joined: 15 February 2006 Status: Offline Points: 250 |
Post Options
Thanks(0)
|
I ended up doing it from the end up. However, you may want to look at the RemoveAt code sample in the documentation. It's doing what I was doing, which didn't work.
Thanks! |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |