Print Page | Close Window

SOLVED: Delete Rows and Childs

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=11560
Printed Date: 08 May 2024 at 12:19am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: SOLVED: Delete Rows and Childs
Posted By: markmark
Subject: SOLVED: Delete Rows and Childs
Date Posted: 24 July 2008 at 3:46am

Hi it’s me again (I'm Sorry)

 

This time I am trying to delete rows from the report.

 

First I tried:

Dim grdReportRow As ReportRow

For Each grdReportRow In wndReportControl.SelectedRows

  If grdReportRow.GroupRow = False Then

         wndReportControl.Records.RemoveAt (grdReportRow.Record.Index)

  End If

Next

 

But if the row is a child the index starts again, and so the deleted row is not the selected row.

 

Then I try

Dim grdReportRow As ReportRow
For Each grdReportRow In wndReportControl.SelectedRows

  If grdReportRow.GroupRow = False Then

        Call wndReportControl.RemoveRowEx(grdReportRow)

  End If

Next

 

 

This seems to work except it will crash.

See example.

In the zip is a Picture with the selection you need to make to cause the crash.

 

 

All I want is to be able to multi select the rows and delete them.

 

 

Thanks for your help

 

MArk
https://forum.codejock.com/uploads/20080724_034601_deleterows.zip - uploads/20080724_034601_deleterows.zip


-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0



Replies:
Posted By: Aaron
Date Posted: 24 July 2008 at 6:09am
Hi,
 
There's something missing in the sample with adding the records. My guess is, that the remove method is working as expected, but some references are missing in record collection or SelectedRows collection.
 
I suggest you report this to support 
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: Peter59
Date Posted: 24 July 2008 at 8:20am
Hi,

try to delete selected rows backwards:

    Dim rptRow As XtremeReportControl.ReportRow
    Dim i As Integer

    For i = (wndReportControl.SelectedRows.Count - 1) To 0 Step -1
        Set rptRow = wndReportControl.SelectedRows.Row(i)
            Debug.Print "about deleting rowindex "; rptRow.Index
        wndReportControl.RemoveRowEx rptRow
    Next i

    wndReportControl.Populate

I could imagine that the cause of the problem is that the internal row collection is reordered every time you delete a row - if you are using and deleting rows with childs. Maybe support can tell us, why deleting selected rows the forward way is crashing.

See the modified sample for a working solution. uploads/20080724_034601_deleterows.zip - uploads/20080724_034601_deleterows.zip

Finally this workaround is better than nothing 

Don't forget to add "SOLVED" to the topic when your problem is solved.




-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows 7 64 Bit
Language: Visual Basic 6.0 SP6


Posted By: Aaron
Date Posted: 24 July 2008 at 8:35am
Hi Peter,
 
Doesn't matter how you do this, seems that some references are lost on the way. Look at the image and try to delete the selected records. You will see that only the first selected record will be deleted and strangely enough the record after the second record and it's childs as well. That's why it crashes...
 
I have a simular problem with the UpdateRecord method, this seems almost to have a reference to the next record.  
 
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: Peter59
Date Posted: 24 July 2008 at 8:47am
Originally posted by Aaron Aaron wrote:

 
Doesn't matter how you do this, [...]
 


Maybe you are right, but I don't worry about it when there is a workaround. I hope that this forum is read by CJ support and they will investigate the problem.

I deleted the selected two rows with the modified sample and it works - or am I wrong?




-------------
Product: Xtreme SuitePro (ActiveX) version 15.2.1
Platform: Windows 7 64 Bit
Language: Visual Basic 6.0 SP6


Posted By: Aaron
Date Posted: 24 July 2008 at 9:07am
Hi Peter,
 
If you upload sample, please add the right code to it  I was testing with the old code from @markmark. To be honest I didn't look at the code as I wrote the previous reply. But it seems to be working as you say
 
Thanks


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: markmark
Date Posted: 25 July 2008 at 5:50am

Hi All

 

Thanks for all the replies

 

I did contact support and this morning I got a reply.

They said to use the following code

 

Dim grdReportRow As ReportRow

For Each grdReportRow In wndReportControl.SelectedRows

 If grdReportRow.GroupRow = False Then

 

       Call wndReportControl.RemoveRowEx(grdReportRow)

 

 End If

 

Next

 

 

However:

 

This does not work if you select a child row.

It seems that the index for a child row starts again.

 

If you copy that code in the example I sent, you will see that selecting a child row and then run the delete code causes another row to delete.

 

Or may be I’m missing the point in all this.

 

I will now try Peters code and see what happens

 

Thanks again

 

MArk

-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0


Posted By: Aaron
Date Posted: 25 July 2008 at 6:36am
Hi,
 
That is correct!!! Support didn't test this properly. If you use Peter's code it will work
 
Think I have something to do right now


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: markmark
Date Posted: 25 July 2008 at 12:29pm

Hi

 

Peters Code is spot on.

I did make a small addition (In Blue)

 

    For i = (wndReportControl.SelectedRows.Count - 1) To 0 Step -1

            If wndReportControl.SelectedRows.Count > 0 Then

                lngCurrentCount = wndReportControl.SelectedRows.Count

                Set rptRow = wndReportControl.SelectedRows.Row(i)

               

                 wndReportControl.RemoveRowEx rptRow

                

                 If lngCurrentCount - 1 > wndReportControl.SelectedRows.Count Then

                        i = i - 1

                 End If

            End If

       

    Next i

 

If you have  wndReportControl.GroupsOrder.Add Column added,

so that the report groups by a column, its possible to select the group which adds to the selection count.

But when that groups items are deleted the group row deletes its self.

and is also removed from the SelectedRows object.

So the count has changed, and variable i  need updating 

Hope that makes sense.

 

I hope CJ will help, as its not very elegant.

 

Thanks to you all

 

 

MArk



-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0


Posted By: AndreiM
Date Posted: 27 July 2008 at 11:11am
Hello,
 
the problem is that SelectedRows collection used row indexes and RemoveRowEx does not update them.
 
To avoid this problem just save selected rows objects in separate collection.
EXAMPLE:
 
    Dim grdReportRow As ReportRow
    Dim arToDel As New Collection
   
    For Each grdReportRow In wndReportControl.SelectedRows
        If grdReportRow.GroupRow = False Then
            arToDel.Add grdReportRow
        End If
    Next
 
    For Each grdReportRow In arToDel
        Call wndReportControl.RemoveRowEx(grdReportRow)
    Next
 
I will think about fixing RemoveRowEx to update SelectedRows collection


-------------
Regards,
Andrei Melnik


Posted By: markmark
Date Posted: 27 July 2008 at 11:33am
Thanks you AndreiM
 
Your code works good.
 
Thanks for looking into this
 
 
 
Regards
 
MArk


-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0


Posted By: AndreiM
Date Posted: 02 August 2008 at 6:19am
Hello,
I have looked in RemoveRowEx implementation and find that row is removed from selected rows collection too.
Let me advice  other simple way to delete rows:
---------------------------------------------------------------------
  Dim grdReportRow As ReportRow
 
  While wndReportControl.SelectedRows.Count
      Set grdReportRow = wndReportControl.SelectedRows(0)
 
      Call wndReportControl.RemoveRowEx(grdReportRow)
  Wend


-------------
Regards,
Andrei Melnik


Posted By: markmark
Date Posted: 02 August 2008 at 6:54am
Hi AndreiM
 
Thats very good. Much better looking and works!
 
Thanks very much
 
MArk


-------------
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0



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