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
55
Filling a UltraCombo via UltraDataSource at runtime does'nt work
posted

Hi !

I want to fill a UltraCombo ("dataSourceExcelSheets") with items via UltraDataSource ("excelSheetCombo") at runtime.
The filling of the UltraDataSource will be invoked at runtime via a button event Click.

The UltraCombo's DataSource will be set in the InitializeComponent() method

     this.excelSheetCombo.DataSource = this.dataSourceExcelSheets;

Problem:
After filling the UltraDataSource it's items will be not shown in the UltraCombo.

Therefore I would be grateful for any help.

Kind regards  

 


The Code

 

        using Excel = Microsoft.Office.Interop.Excel;
 
 
         private void buttonImportExcel_Click(object sender, EventArgs e) {
             Excel.Application   excelApp = null;
             Excel.Workbook    workBook = null;
             Excel.Worksheet  workSheet = null;         
             String                      filename = null;
 
             try {
                 this.openFileDialogExcelImport.ShowDialog();
                 filename = this.openFileDialogExcelImport.FileName;
                 this.filenameLabel.Text = filename;
 
                 // Neue Excel-Instanz erzeugen
                 excelApp = new Excel.ApplicationClass();
                 excelApp.Visible = true;
                 workBook = excelApp.Workbooks.Open(
                     filename,
                     ExcelConst.UpdateLinks.DontUpdate,
                     ExcelConst.ReadOnly,
                     ExcelConst.Format.Nothing,
                     "", // Passwort
                     "", // WriteResPasswort
                     ExcelConst.IgnoreReadOnlyRecommended,
                     Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
                     "", // Trennzeichen
                     ExcelConst.Editable,
                     ExcelConst.DontNotifiy,
                     ExcelConst.Converter.Default,
                     ExcelConst.DontAddToMru,
                     ExcelConst.Local,
                     ExcelConst.CorruptLoad.NormalLoad);
 
                 if (workBook != null) {
                     for (int i = 0; i < workBook.Sheets.Count; i++) {
                         Excel.Worksheet sheet = (Excel.Worksheet)workBook.Sheets[i + 1];
                         this.dataSourceExcelSheets.Rows.AddRange(new object[ {
                                 new Infragistics.Win.UltraWinDataSource.UltraDataRow(new object[ {
                                     ((object)("Nr")),
                                     ((object)(((short)(i)))),
                                     ((object)("Tabellenname")),
                                     ((object)(sheet.Name))})});
                     }
                 }
                 this.excelSheetCombo.DataBind();
             }
             catch (Exception ex) {
                 // Tabellenblatt entsorgen
                 if (workSheet != null)
                     Marshal.ReleaseComObject(workSheet);
 
                 // Mappe entsorgen
                 if (workBook != null)
                     Marshal.ReleaseComObject(workBook);
 
                 // Excel schließen
                 if (excelApp != null) {
                     excelApp.Quit();
                     Marshal.FinalReleaseComObject(excelApp);
                 }
             }
        } 

Parents
No Data
Reply
  • 469350
    Offline posted

        What exactly happens when you drop down the combo? Do you see columns? Do you see anything at all? Are there empty rows or no rows? 

         Try checking the Rows count on the UltraDataSource an the UltraCombo. You might also try checking the count of the Columns in both the UltraDataSource and the Ultracombo.

     

     

Children
No Data