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 8923829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:14:22+00:00 2026-06-15T07:14:22+00:00

Frm Form1 = new Frm(); //here I always get the count =0 if (Form1

  • 0
            Frm Form1 = new Frm();
                //here I always get the count =0
            if (Form1 .listBox2 .SelectedItems .Count  > 0)
            {
                string item;
                foreach (int i in Form1.listBox2.SelectedIndices)
                {
                    item = Form1.listBox2.Items[i].ToString();

and when I do the same in Frm I get the real number of selected items here’s the code in Frm

    public  void btnPostText_Click(object sender, EventArgs e)
    {
        listBox2.ClearSelected();
        if (listBox1.SelectedItems.Count > 0)
        {
            foreach (int index in listBox1.SelectedIndices)
                listBox2.SetSelected(index, true);
        }

from my program I am trying to post to more than one group at facebook at the same time after the log in process the user selects the groups names that he/she wants to post to at litBox1 in listBox2 there’s the groups id(s) in the same order , so when user clicks on the btnPostText I move the selection from listBox1 to listBox2′ ,,, Now in Class2` I want to know if any Items are selected in listBox2 ,, the first code is in Class2. PostImg public static bool PostImg( , , ,)

Class2 contains the post procedures just like the Postimg it returns true if posted or false if not

here I am calling it in Frm

  if (Class2.PostImage(AppSettings.Default.AccessToken, textbox1.Text, textboxpic.Text) == true)
                MessageBox.Show("Post Done");

the code in Class2 is

    public static bool PostImage(string AccessToken, string Status, string ImagePath) 
    {
        try
        {
            Frm Frm = new Frm();

            if (Frm .listBox2 .SelectedItems .Count  > 0)
            {
                string item;
                foreach (int i in Frm.listBox2.SelectedIndices)
                {
                    item = Frm.listBox2.Items[i].ToString();
                    groupid = item;


                    FacebookClient fbpost = new FacebookClient(AccessToken);
                    var imgstream = File.OpenRead(ImagePath);
                    dynamic res = fbpost.Post("/" + groupid + "/photos", new
                   {
                       message = Status,
                       File = new FacebookMediaStream
                       {

                           ContentType = "image/jpg",
                           FileName = Path.GetFileName(ImagePath)
                       }.SetValue(imgstream)

                   });

                    result = true;

                }
            }
            return result;
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
            return false;
        }
  • 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-06-15T07:14:24+00:00Added an answer on June 15, 2026 at 7:14 am

    First things first, some basics. Class2 and Frm are two distinct classes. Normally they cannot see each other unless you pass a reference between them.

    Frm can see the PostImage method inside Class2 because it was marked as static. But it doesn’t go the other way. So you need to pass a reference to Frm when you call PostImage. Easiest way of doing this is including it in the method signature:

    public static bool PostImage(string AccessToken, string Status, string ImagePath, Frm MyForm) 
    

    Now you call it:

    if (Class2.PostImage(AppSettings.Default.AccessToken, textbox1.Text, textboxpic.Text, this) == true)
    

    Notice how we passed this as a parameter in the function. This is the reference we are going to use inside PostImage:

    if (MyForm.listBox2.SelectedItems .Count  > 0)
    

    And so on and so forth. The variable MyForm is now a reference to the form that called Class2.PostImage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider two forms: form1 and form2 form1 calls form2 : form2 frm = new
Form1 frm = new Form1(); frm.mdiParent=this; frm.show(); I want to create a global method
Which is a better way to show a modal dialog? form1 frm=new form1(); frm.showDialog()
Form1 frm = new Form1(); frm1.ShowDialog(); I use this to create new form to
I have 4 info, tat i get frm database. I want to view all
I have a form (for example, abc.frm ). I want the duplicate form (for
Hi I have the following script in my form function pdf() { var frm
I have a JFrame(frm) in which I've added a JPanel (pnl1)..which in turn has
i want to return wchar_t frm a function. How can i implement it wchar_t
I'm trying to post a JavaScript data object with the following: $.post(frm.attr(action), data, function(res)

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.