当前位置: 动力学知识库 > 问答 > 编程问答 >

Lightswitch clear a visualcollection

问题描述:

I have a visualcollection of temporary data. What is the right way to clear all records from this visualcollection?

EDIT (after Yann's request for a better picture of what I'm trying to do)

At the click of a button, I'm populating a visualcollection with data based on user-defined parameters. The user can edit this data as needed. Then when they click Save, I'm writing this data to different database tables. (The reason I'm doing this through code is because the shape of the visualcollection does not map directly to a single table in my SQL database - a scenario Lightswitch does not allow one to accomplish easily, I have noticed.) However, if the user changes the parameters for populating the collection after the collection has been populated, I need to clear that collection and repopulate it based on the new parameters. It is here that I was hoping to just call a [visualcollection].clear method. But non such luck. I've tried each of the following approaches without success:

1) for each item in visualcollection, call item.details.delete (this returns an error something about the item not being tracked by the current context)

2) set the first item to the selecteditem, then call visualcollection.removeselected. Iterate while first item != null. (this one just plainly fails to remove all the items from the collection - it removes some, but not all - I don't understand why).

So now I've gone the route of calling this.Refresh on the screen (after having stored the user's parameters in static variables so that I can repopulate them in the dataworkspaceinitialized event of the screen). This step just seems too drastic though...must I really go as far as calling refresh on the screen to clear a visualcollection?

网友答案:

The "best" way can depend on a few different things, is it an attached database, or the intrinsic database? Are you familiar with triggering code on the server from the client? How many records are involved etc? Is there an existing process where this could just be a natural part of it? Or are you intending to have the operation performed at the click of a button on a screen?

As you can see, it's not a simple answer, without knowing more about what you want to do.

分享给朋友:
您可能感兴趣的文章:
随机阅读: