Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
Define my own UltraDataSource with my columns...
posted

Hey Mike,

 I am creating a derived UltraDataSource that has my own custom columns.  I have been using the ctor to create the columns (the setup proc is called by the ctor):

private void SetUp() {

_colName = this.Band.Columns.Add("CalendarName", typeof(string));

_colAccessLevel = this.Band.Columns.Add("AccessLevel", typeof(string));

_colDateCreated = this.Band.Columns.Add("DateCreated", typeof(DateTime));

_colDateUpdated = this.Band.Columns.Add("DateUpdated", typeof(DateTime));

_colOwner = this.Band.Columns.Add("CalendarOwner", typeof(string));

}

But when I put this on a form and bind it to a grid, I get this designercode:

ultraDataColumn3.DataType = typeof(System.DateTime);

ultraDataColumn4.DataType = typeof(System.DateTime);

this.udsGoogleCals1.Band.Columns.AddRange(new object[ {

ultraDataColumn1,

ultraDataColumn2,

ultraDataColumn3,

ultraDataColumn4,

ultraDataColumn5});

Which throws a key already exists.  So the ctor is not the place to define the columns.

 Where should I do this?  Is there another way to get around not having to comment out this designer code (which I am now going to confession for...).

 

Thanks!

Bob 

 

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Bob,

    This makes sense because when you place your derived UltraDataSource on the form at design-time, it will fire it's constructor and create the columns. The columns are also serialized to the form. Then when you run the application, a new component is created and the constructor is called, which creates the columns. Then the deserialization code will get called and try to create them again. 

    So you need to set this up so it only creates the columns the first time the control is created. For a control, I would normally recommend that you override OnCreateControl.

    There doesn't seem to be a similar method of Components, though. So the only thing I can think of is that you do not create the component at design-time, but instead create it at run-time. Perhaps in the Form_Load event. That way you aboid the serialziation/ deserialization of the columns. 

     

Reply Children