8 Replies - 8836 Views - Last Post: 10 May 2010 - 09:17 AM Rate Topic: -----

#1 alibahaloo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-May 10

Passing data from one form to another

Posted 09 May 2010 - 11:02 AM

hi people
i'm havin' a problem with my winForm app...
i'm trying to pass data from a from to another...consider this:
form one has a control; listbox
form two has holds a string variable:
string[] can = {"item1","item2","item3"};

and i wanna do:
listbox.DataSource = can;

so in form one the list box displays the string list sent from from two... notice that form comes up first and when event (speech recognized) is triggered.

so, the first form comes up and in there i have that string (can) as the data source and in the other form i my list box, i wonder how i can pass the string when an event is triggered...

appreciate your help

Is This A Good Question/Topic? 0
  • +

Replies To: Passing data from one form to another

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1020
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Passing data from one form to another

Posted 09 May 2010 - 11:26 AM

This has been asked on this forum at least a million times. Maybe a little searching would help.
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: Passing data from one form to another

Posted 09 May 2010 - 12:09 PM

Quote

This has been asked on this forum at least a million times. Maybe a little searching would help.


So much so that it should probably be a sticky thread pointing directly to the tutorial.
Was This Post Helpful? 1
  • +
  • -

#4 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Passing data from one form to another

Posted 09 May 2010 - 01:25 PM

Declare your string as public inside your form2.
Then before closing Form2 in the Main Form do the instruction.
Was This Post Helpful? 1
  • +
  • -

#5 alibahaloo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-May 10

Re: Passing data from one form to another

Posted 10 May 2010 - 03:40 AM

View Postponcho4all, on 09 May 2010 - 12:25 PM, said:

Declare your string as public inside your form2.
Then before closing Form2 in the Main Form do the instruction.


yes, declaring a variable in the other form works as you say...
but i want to access the listbox.items property directly, that is because, i have method that returns a percentage value from comparing a string to another string, so when a user speaks something, that "something" is compared to whole list of words and returns a string list based on that comparison, so if one says "life", the string list would be { "life", "like","love","live" }. at this point i want the listbox to be loaded with that string... and this happens every time the users says something, so the list is updated every time a recognition is occurred:
void dic_objgrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            alternatives_listbox.Items.Add(e.Result.Text);
            //listView1.Items.Add(e.Result.Text);
        }


this gives the following message:

Quote

Cross-thread operation not valid: Control 'alternatives_listbox' accessed from a thread other than the thread it was created on.

as i understand it, this happens since recognition is handled in a different thread and i can't access my winForm controls from that thread...

please help me on this issue, i search for some examples, but i couldn't find anything that is easy to learn, instead of saying "This has been asked on this forum at least a million times. Maybe a little searching would help." , post a link of one of those "millions"...

thanks
Was This Post Helpful? 0
  • +
  • -

#6 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1020
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Passing data from one form to another

Posted 10 May 2010 - 05:47 AM

http://www.dreaminco...to-parent-form/
http://www.dreaminco...-forms-in-c%23/
http://www.dreaminco...a-between-form/
http://www.dreaminco...-c%23-or-vbnet/

Took me 3 seconds to find these by using the search function on the page you are viewing right now. If you won't help yourself, don't expect others to do so.
Was This Post Helpful? 2
  • +
  • -

#7 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Passing data from one form to another

Posted 10 May 2010 - 06:55 AM

So you want to access the main form listbox from the Form2?
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Passing data from one form to another

Posted 10 May 2010 - 07:03 AM

Regarding cross-thread communication, here's a tutorial on it.
Was This Post Helpful? 0
  • +
  • -

#9 alibahaloo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-May 10

Re: Passing data from one form to another

Posted 10 May 2010 - 09:17 AM

View Postponcho4all, on 10 May 2010 - 05:55 AM, said:

So you want to access the main form listbox from the Form2?

no, the string is on the main form, and the list box is on form 2... at the recognition event ( which is on main form) i assemble the string, and then i want to open form 2 and load that string to listbox
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1