Desktop version

Main > Forum > 1C:Enterprise Platform > Studying 1C:Enterprise platform > How to delete rows from the tabular section?

Forum

Search UsersRules
How to delete rows from the tabular section?
#1
Active user
Points:: 0
Joined:: Sep 27, 2011

Hi!

I need to add a command which removes services from the document tabular section, here is my code:

Code
   For Each Row In Object.Goods Do
      If Row.Item.Type = Enums.ItemTypes.Service Then
         Object.Goods.Delete(Row.LineNumber - 1);
      EndIf;
   EndDo;

It works, but sometimes not all lines are deleted.

Profile
#2
Active user
Points:: 0
Joined:: Sep 26, 2012

I think you need begin delete rows from end :)
Try this:

Code
countRows = Object.Goods.Count();
For i = 1 to countRows Do
  Row = Object.Goods[countRows - i];
  If Row.Item.Type = Enums.ItemTypes.Service Then
     Object.Goods.Delete(Row.LineNumber - 1);
  EndIf;
EndDo;

Profile
#3
Just came
Points:: 0
Joined:: May 5, 2012

The problem occur when rows ,that is needed to delete, stand in line one by one, because quantity of tabular section decreases on 1 but operator "For Each" continues to work with old indexes and skips row that is needed to delete but it's behind current iteration.
You can overcome this problem like this:

Code
DeleteRow = True;
While DeleteRow Do
   For Each Row In Object.Goods Do
      If Row.Item.Type = Enums.ItemTypes.Service Then
         Object.Goods.Delete(Row.LineNumber - 1);
       DeleteRow = True;
         Continue;
     Else 
       DeleteRow = False;
      EndIf;
   EndDo;
EndDo;

Profile
#4
Active user
Points:: 0
Joined:: Sep 27, 2011

Wery smart idea to delete them from behind, who could guess? Thanks, ivan!
Interesting idea, Bogdan Sinitsa

Profile
#5
Active user
Points:: 0
Joined:: Jun 4, 2013

I was trying to delete a raw  from a different catalog but I couldn't .... do you have any idea to do that ?!

I tried like this but it didnt work

Code
  a=Catalogs.Workers.FindByDescription("kamil namli").GetObject().workersTable ;
      for each i in a do
       i.delete(i.LineNumber-1);
      enddo


there is no delete method when you use  FindByDescription :S

thanks in advance :)

Profile
#6
Active user
Points:: 0
Joined:: Sep 26, 2012

try so:

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();
for each i in a.workersTable do
  a.workersTable.delete(i);
enddo;

a.Write();


In your example method "delete" used to "i", where "i" is line of a tabular section. But this method applied to tabular section.

Profile
#7
Active user
Points:: 0
Joined:: Nov 1, 2011

First of all, you should check if such an item exist.
Then loop from the end to begining.

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();

If Not a=Undefined Then
    RowCount = a.workersTable.Count();
    For i=1 to RowCount do
        a.workersTable.Delete(RowCount-i);
    EndDo;
    a.Write();
EndIf;


And after all, if you want to delete all rows you should use Clear() method.

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();

If Not a=Undefined Then
    a.workersTable.Clear();
    a.Write();
EndIf;

Profile
#8
Active user
Points:: 0
Joined:: Jun 4, 2013

thanks a lot  .. and no I don't want to delete all the rows ... the delete method has worked perfectly

Profile
#9
Just came
Points:: 0
Joined:: Nov 1, 2011

Hi!
You have to create an array, fill it with rows to be deleted.
Then, in a loop around the array and calls the tables of Delete, as a parameter to pass an array element.

Profile
#10
Just came
Points:: 0
Joined:: Nov 1, 2011

Example:

Code
DeleteRows = New Array;

For Each Row In Object.Goods Do
   If Row.Item.Type = Enums.ItemTypes.Service Then
      DeleteRows.Add(Row);    
   EndIf;
EndDo;

For Each DelRow In DeleteRows  Do
   Object.Goods.Delete(DelRow);
EndDo;

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.