private void BindWeatherReportToRange(object weatherDatasource, CellRange bindingRange) { Worksheet sheet = spreadsheetControl1.Document.Worksheets[0]; // Check for range conflicts. var dataBindingConflicts = sheet.DataBindings. Where(d => (d.Range.RightColumnIndex >= bindingRange.LeftColumnIndex) || (d.Range.BottomRowIndex >= bindingRange.TopRowIndex)); if (dataBindingConflicts.Count() > 0) { MessageBox.Show("Cannot bind the range to data.\r\nThe worksheet contains other binding ranges which may conflict.", "Range Conflict"); return; } // Specify the binding options. ExternalDataSourceOptions dsOptions = new ExternalDataSourceOptions(); dsOptions.ImportHeaders = true; dsOptions.CellValueConverter = new MyWeatherConverter(); dsOptions.SkipHiddenRows = true; // Bind the data source to the worksheet range. WorksheetDataBinding sheetDataBinding = sheet.DataBindings.BindToDataSource(weatherDatasource, bindingRange, dsOptions); // Adjust the column width. sheetDataBinding.Range.AutoFitColumns(); }
private void barBtnUnbind_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) { foreach (WorksheetDataBinding wdb in spreadsheetControl1.Document.Worksheets[0].DataBindings) { wdb.Range.FillColor = System.Drawing.Color.Empty; } weatherDataBinding = null; fishesDataBinding = null; spreadsheetControl1.Document.Worksheets[0].DataBindings.Clear(); }
private void barBtnBindMyFishes_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) { // Specify the binding options. ExternalDataSourceOptions dsOptions = new ExternalDataSourceOptions(); dsOptions.ImportHeaders = true; // Bind the data source to the worksheet range. this.fishesDataBinding = spreadsheetControl1.Document.Worksheets[0].DataBindings.BindToDataSource(MyFishesSource.Data, 2, 5, dsOptions); // Highlight the binding range. this.fishesDataBinding.Range.FillColor = System.Drawing.Color.LightCyan; // Adjust column width. spreadsheetControl1.Document.Worksheets[0].Range.FromLTRB(5, 2, this.fishesDataBinding.Range.RightColumnIndex, this.fishesDataBinding.Range.BottomRowIndex).AutoFitColumns(); }
private void BindWeatherReport(object weatherDatasource) { if (this.weatherDataBinding != null) { spreadsheetControl1.Document.Worksheets[0].DataBindings.Remove(this.weatherDataBinding); } #region #BindTheList // Specify the binding options. ExternalDataSourceOptions dsOptions = new ExternalDataSourceOptions(); dsOptions.ImportHeaders = true; dsOptions.CellValueConverter = new MyWeatherConverter(); dsOptions.SkipHiddenRows = true; // Bind the data source to the worksheet range. Worksheet sheet = spreadsheetControl1.Document.Worksheets[0]; WorksheetDataBinding sheetDataBinding = sheet.DataBindings.BindToDataSource(weatherDatasource, 2, 1, dsOptions); #endregion #BindTheList this.weatherDataBinding = sheetDataBinding; // Highlight the binding range. this.weatherDataBinding.Range.FillColor = System.Drawing.Color.Lavender; // Adjust column width. spreadsheetControl1.Document.Worksheets[0].Range.FromLTRB(1, 1, this.weatherDataBinding.Range.RightColumnIndex, this.weatherDataBinding.Range.BottomRowIndex).AutoFitColumns(); }