Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# checkedlistbox.items.add problem

Posted on 2011-02-16
12
Medium Priority
?
1,212 Views
Last Modified: 2013-12-17
I am trying to have a checklistbox populate from certain criteria out of an excel spread sheet. When the code reaches the Microsoft.Office.Interop.Excel.Application xl portion of the code. The Form disappears and then reappears but the code will not run past this point. What am I doing wrong?


********************************************************************************************************************
int cntr = 2;
            Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
            Workbook wb = xl.Workbooks.Open(@"C:\Users\rciner\Documents\GROUP MUSTER.xls", 0, false, false, false, false, true, Missing.Value, Missing.Value, true, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
           
            xl.Visible = true;
            Worksheet ws = (Worksheet)wb.Worksheets[1];
            Range aRange = ws.get_Range("a" + Convert.ToString(cntr), Missing.Value);
            Range lRange = ws.get_Range("l" + Convert.ToString(cntr), Missing.Value);

            checkedListBox1.Items.Add("ciner");
0
Comment
Question by:rciner313
  • 6
  • 5
12 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 34913527
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34913835
Have you put a breakpoint and checked values of xl, wb, ws...
0
 

Author Comment

by:rciner313
ID: 34915570
I have put a break point in and i got the error : A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in MOB_Traning_Data.exe

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34915759
OK - so that is why it stops.

Do you have Excel installed on this PC ?
0
 

Author Comment

by:rciner313
ID: 34921054
when i press F5 to continue the program past the break point it does not respond. I have excel on this PC and I have used this method for comboboxes and it works there, just not with the checklistbox.items.add portion.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34923838
Exactly which line results in this error you get ?
0
 

Author Comment

by:rciner313
ID: 34929834
Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34930051
>>I have used this method for comboboxes

In this application?
Check if you do something different in code prior to the above line (I assume you do use the same line of code)
0
 

Author Comment

by:rciner313
ID: 34930111
I have typed it out and copied and pasted it, nothing seems to work. Here is a samples from a place where it works. I am wondering if there is a glitch with the private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) that causes the freeze with a checked list box:

int cntr=0;
            char col = 'a';
            int colcntr = 0;
            int lccntr = 1;
            cntr = comboBox2.SelectedIndex + 2;
            colcntr = comboBox1.SelectedIndex + 1;
            Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 34931939
I've never tried to automate excel (or other COM based application) from a managed (eg. C#) application.  From unmanaged code (C++) one needed to 'start' support of COM via a fuction call BEFORE any attempt to use it was made.  Typically this would be done at application start (and the shutdown of COM support was performed when the app was stopped).

I'll see if I have time next week to make a small automation of excel attempt from C# code.
0
 

Accepted Solution

by:
rciner313 earned 0 total points
ID: 34955740
The problem seemed to be a conflict with the software. I reloaded windows 7 and c# and now it works. Thanks for your help though.
0
 

Author Closing Comment

by:rciner313
ID: 34990864
I reloaded windows 7 and c# and now the problem is solved
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question