Tuesday, March 20, 2012

Conditionally adding a column to my custom component (part 2)

A month or so ago I instigated this thread- http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=243117&SiteID=1 which talked about how to conditionally add a column to my component depending on the value of a custom property. If the custom property is TRUE then the column should appear in the output (and vice versa).

Bob Bojanic said I should use the SetComponentProperty() method to do this and that is working pretty well. However, it bothers me that SetComponentProperty() could be called, the column will then be added, and then the package developer could press 'Cancel'. In this instance the value of my custom property would be inconsistent with the presence of the extra column.

How do you get around that?

Thanks

Jamie

This is what component views are for. Call the GetComponentView method to create a view of the component. Then make all your changes to the component. If the user selects OK then call commit on the view. If the user selects cancel then call Cancel on the view. The view keeps track of all changes and commit saves them to the component and cancel discards all the changes.

Thanks,

Matt

|||

To get OK/Cancel functionaility in a component UI, for free, make sure you make all changes through the CManagedComponentWrapper instance of your component, not the component direct. I go on about this in the book, download the samples to see an example.

metaData is IDTSComponentMetaData90 normally passed on the form Ctor or your own setup method , comming from the UI class. Then call "CManagedComponentWrapper wrapper = metaData.Instantiate();" to get the wrapper.

Update - Matt are you sure about GetComponentView, was that not dropped or at least you no longer need to do it, sometime after beta 2 I think. The bool result from IDtsComponentUI.Edit is now sufficient to commit or rollback the changes made through the wrapper.

|||

Darren,

Yes, I am sure but the caveat here is that I always think in native code and everyone else thinks in managed code. For native code you need to use views. For managed code it does the views for you without your knowledge (please disregard the man behind the screen ).

Thanks,

Matt

sqlsql

No comments:

Post a Comment