protected virtual void AddAutoBindColumns(PDFDataContext context) { if (string.IsNullOrEmpty(this.DataSourceID)) { throw new InvalidOperationException("Can only auto bind the schema when the DataGrid has an explicit DataSourceID and the referencing source supports Schema derriving"); } IPDFDataSource found = base.FindDocumentComponentById(this.DataSourceID) as IPDFDataSource; if (null == found || found.SupportsDataSchema == false) { throw new InvalidOperationException("Can only auto bind the schema when the DataGrid has an explicit DataSourceID and the referencing source supports Schema derriving"); } PDFDataSchema schema = found.GetDataSchema(this.SelectPath, context); if (null == schema || schema.Items == null || schema.Items.Count == 0) { context.TraceLog.Add(TraceLevel.Warning, "PDFDataGrid", string.Format("Cannot autobind the columns as no schema items were returned for the path '{0}'", this.SelectPath)); } else { foreach (PDFDataItem item in schema.Items) { if (ShouldIncludeAutoBoundItem(item)) { DataGridColumn col = GetDataColumnForType(item.DataType); if (null != col) { col.HeaderText = string.IsNullOrEmpty(item.Title) ? item.Name : item.Title; col.SetDataSourceBindingItem(item, context); if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "PDFDataGrid", string.Format("The data column was automatically created for the schdema item '{0}' in data grid '{1}'", item, this)); } this.Columns.Add(col); } } } } }
protected virtual void AddAutoBindFields(object data, IPDFDataSource source, PDFDataContext context) { if (string.IsNullOrEmpty(this.DataSourceID)) { throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving"); } IPDFDataSource found = base.FindDocumentComponentById(this.DataSourceID) as IPDFDataSource; if (null == found || found.SupportsDataSchema == false) { throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving"); } PDFDataSchema schema = found.GetDataSchema(this.SelectPath, context); if (null == schema || schema.Items == null || schema.Items.Count == 0) { context.TraceLog.Add(TraceLevel.Warning, "PDFWithFieldSet", string.Format("Cannot autobind the columns as no schema items were returned for the path '{0}'", this.SelectPath)); } else { if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "DataGrid", "Initializing and loading root component before binding"); } PDFTraceLog log = context.TraceLog; PDFInitContext init = new PDFInitContext(context.Items, log, context.PerformanceMonitor, this.Document); PDFLoadContext load = new PDFLoadContext(context.Items, log, context.PerformanceMonitor, this.Document); foreach (PDFDataItem item in schema.Items) { if (ShouldIncludeAutoBoundItem(item)) { WithBoundField field = GetFieldForType(item.DataType); if (null != field) { field.StyleClass = this.FieldClass; field.FieldLabel = string.IsNullOrEmpty(item.Title) ? item.Name : item.Title; field.LabelClass = this.LabelClass; field.ValueClass = this.ValueClass; field.LabelPostFix = this.LabelPostFix; field.LayoutType = this.AutoLayoutType; field.DataType = item.DataType; field.HideIfEmpty = this.HideEmptyFields; field.SetDataSourceBindingItem(item, context); if (context.TraceLog.ShouldLog(TraceLevel.Debug)) { context.TraceLog.Add(TraceLevel.Debug, "PDFWithFieldSet", string.Format("The data field was automatically created for the schdema item '{0}' in set '{1}'", item, this)); } this.Fields.Add(field); field.Init(init); field.Load(load); this.BindingActions.Add(new BindingAction(data, source, field)); } } } //added all the items } }