Print Page | Close Window

RemoveAt Revisited

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=4100
Printed Date: 19 September 2024 at 1:10pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: RemoveAt Revisited
Posted By: Gutauckis
Subject: RemoveAt Revisited
Date 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?



Replies:
Posted By: Gutauckis
Date Posted: 30 April 2006 at 8:22pm
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




Posted By: sserge
Date Posted: 01 May 2006 at 4:39am
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


Posted By: Gutauckis
Date Posted: 01 May 2006 at 2:44pm

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...



Posted By: sserge
Date Posted: 01 May 2006 at 6:10pm
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


Posted By: Waescher
Date Posted: 16 October 2006 at 11:16am
Yes, that did it, great topic!

i really tried to solve that problem in my app without any success!

Thank you!



Posted By: jcollier
Date Posted: 16 October 2006 at 5:56pm
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



Posted By: sserge
Date Posted: 17 October 2006 at 12:40pm
Originally posted by jcollier jcollier wrote:

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



I would not recommend this. Better to use RemoveAll

--
WBR,
Serge


Posted By: jcollier
Date Posted: 17 October 2006 at 1:22pm
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.



Posted By: sserge
Date Posted: 18 October 2006 at 2:41am
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


Posted By: jcollier
Date Posted: 18 October 2006 at 11:46am
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!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net