Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Report Control
  New Posts New Posts RSS Feed - RemoveAt Revisited
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

RemoveAt Revisited

 Post Reply Post Reply
Author
Message
Gutauckis View Drop Down
Newbie
Newbie


Joined: 06 December 2004
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gutauckis Quote  Post ReplyReply Direct Link To This Post Topic: RemoveAt Revisited
    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?
Back to Top
Gutauckis View Drop Down
Newbie
Newbie


Joined: 06 December 2004
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gutauckis Quote  Post ReplyReply Direct Link To This Post 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


Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Gutauckis View Drop Down
Newbie
Newbie


Joined: 06 December 2004
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gutauckis Quote  Post ReplyReply Direct Link To This Post 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...

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Waescher View Drop Down
Newbie
Newbie


Joined: 15 September 2006
Location: Germany
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote Waescher Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
jcollier View Drop Down
Senior Member
Senior Member


Joined: 15 February 2006
Status: Offline
Points: 250
Post Options Post Options   Thanks (0) Thanks(0)   Quote jcollier Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jcollier View Drop Down
Senior Member
Senior Member


Joined: 15 February 2006
Status: Offline
Points: 250
Post Options Post Options   Thanks (0) Thanks(0)   Quote jcollier Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jcollier View Drop Down
Senior Member
Senior Member


Joined: 15 February 2006
Status: Offline
Points: 250
Post Options Post Options   Thanks (0) Thanks(0)   Quote jcollier Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.