I have two combobox (combobox1 in form 1 and combobox2 in form2). I need to import an excel file and the combobox1 gets the sheets name. Then in the form2 (I don't want to import the same file another time) i have combobox2 that have also the same sheets name from the combobox1.
I tried this but i got the error of NULLFUNCTION Expression(Additional Information: The object reference is not set to an instance of an object).
using (OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "Excel 97-2003 Workbook|*.xls|Excel Workbook|*.xlsx |fichiers Textes (*.txt)|*.txt|fichiers CSV (*.csv)|*.csv|tous les fichiers (*.*)|*.*" })
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
TextBox_Emplacement.Text = openFileDialog.FileName;
using (var stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true }
});
dataTableCollection = result.Tables;
dataTableCollection1 = result.Tables;
sheet.Items.Clear();
//cp.radDropDownList1.Items.Clear();
foreach (DataTable table in dataTableCollection)
sheet.Items.Add(table.TableName);//add sheet to combobox
**Form_Copie cp1 = (Form_Copie)Application.OpenForms["Form_Copie"];
foreach (DataTable table in dataTableCollection)
cp1.radDropDownList1.Items.Add(table.TableName);//add sheet to combobox**