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 actual number of elements selected here is 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, which I try to send to more than one group on facebook simultaneously after the registration process, the user selects the names of the groups that he / she wants to publish to litBox1 in listBox2, there are the identifiers of the groups (s) in the same order, therefore, when the user clicks on btnPostText, I move the selection from listBox1 to listBox2 ', Now in Class2` I want to know if any items were selected in listBox2, the first code is in Class2. PostImg public static bool PostImg (,,)
Class2 contains mail routines like Postimg, which returns true if sent or false if not
here i call 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; }