Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3226652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:28:55+00:00 2026-05-17T16:28:55+00:00

In my win forms app I have a listbox and a textbox the app

  • 0

In my win forms app I have a listbox and a textbox the app gets email from a server and displays the subject etc in the listbox and when I click the listbox the body is shown in the textbox. The problem is I have to repeat the entire code below in the selected index changed event to get it to work otherwise I get “does not exists in current context” error this slows down the app.

// Create an object, connect to the IMAP server, login,
        // and select a mailbox.
        Chilkat.Imap imap = new Chilkat.Imap();
        imap.UnlockComponent("");
        imap.Port = 993;
        imap.Ssl = true;
        imap.Connect("imap.gmail.com");
        imap.Login("user@email.com", "pass");
        imap.SelectMailbox("Inbox");

        // Get a message set containing all the message IDs
        // in the selected mailbox.
        Chilkat.MessageSet msgSet;
        msgSet = imap.Search("ALL", true);

        // Fetch all the mail into a bundle object.
        Chilkat.EmailBundle bundle = new Chilkat.EmailBundle();
        bundle = imap.FetchBundle(msgSet);

        // Loop over the bundle and display the From and Subject.
        Chilkat.Email email;
        int i;
        for (i = 0; i < bundle.MessageCount - 1; i++)
        {

            email = bundle.GetEmail(i);
            listView1.Items.Add(email.From + ": " + email.Subject).Tag = i;


            richTextBox1.Text = email.Body;

        }

        // Save the email to an XML file
        bundle.SaveXml("bundle.xml");

and here is the code I would like to get to work in the selected index changed event:

 if (listView1.SelectedItems.Count > 0)
        {
            richTextBox1.Text = bundle.GetEmail((int)listView1.SelectedItems[0].Tag).Body;
        }

When I use this code I get the error “bundle does not exist in the current context”; how do I fix this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:28:55+00:00Added an answer on May 17, 2026 at 4:28 pm

    It seems that you have to redesign your code so that the object you are interested in is available in the context that needs it. One solution might be:

    class Form1
    {
     ...
    
     // You need to have the bundle available in your event handler, so it should be 
     // a field (or property) on the form:
     Chilkat.EmailBundle bundle;
    
     // Call this e.g. on start up and possibly when a
     // refresh button is clicked:
     protected void RefreshMailBox()
     {
      Chilkat.Imap imap = new Chilkat.Imap();
      imap.UnlockComponent("");
      imap.Port = 993;
      imap.Ssl = true;
      imap.Connect("imap.gmail.com");
      imap.Login("user@email.com", "pass");
      imap.SelectMailbox("Inbox");
    
      Chilkat.MessageSet msgSet = imap.Search("ALL", true); 
      bundle = imap.FetchBundle(msgSet);
     }
    
     protected void YourEventHandler()
     {
      if (listView1.SelectedItems.Count > 0)
      {
       // bundle is now accessible in your event handler:
       richTextBox1.Text = bundle.GetEmail((int)listView1.SelectedItems[0].Tag).Body;
      }
     }
    
     ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class in my C# .NET 3.5 win forms app: class
I have a win forms app that needs to allow the user to select
So we have a winforms app that in the task manager should anywhere from
I'm working on a WinForms app and I have a user control in it.
I have a WinForms app written in C# with .NET 3.5. It runs a
I have a winforms app and i want to keep track of every time
I have a WinForms app with a datagridview and a bindingsource. I want the
I have a .net winforms app which has a few animation effects, fade ins
Problem 1: I have a simple winforms app and I want to DataBind my
In my C# winforms app, I have a datagrid. When the datagrid reloads, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.