[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Help with C# programming listbox and arrays

I have three forms (frm1,frm2,frm3).  The first frm1 contains a listbox1,button1,listbox2, button2.
button1 opens up frm2, button2 opens up frm3.  

When i click button1, it open up frm2, frm2.listbox is filled with items to choose from, i need to select from frm2.listbox and return the items to frm1.listbox1.
when i click button2, it open up frm3, it takes the values from frm1.listbox1 items and is put in new sql search string, returns items to frm3.listbox1, user can now select which item he wants by clicking on button (>>) to move to frm3.listbox1.  

When he clicks OK button on frm3, frm3 closes, frm3.listbox1 is set equal to frm1.listbox2.

Need help with passing frm1.listbox1 and frm1.listbox2 items to frm3 and returning results to frm1.  
0
schen
Asked:
schen
  • 2
1 Solution
 
Gautham JanardhanCommented:
to pass variable to a form what u could do is overload the form constructor


//constructor form 1
public void Form1(string AVariable)
{
}

//creating form 1

Form obj = new Form1(listbox.selectedvalue.tostring())

for retreiiving values from the form what u could do is
decalre a  variable in the form an set it to the value u want to return
//sample code below



Form obj = new Form1(listbox.selectedvalue.tostring());
//ShowDIalog()-----not Show()//Important
obj.ShowDialog();
//Value is the string decalre in the form which containds the value of the selected item
obj.Value


0
 
Gautham JanardhanCommented:
add to that above
//creating form 1
string AValue;
string AreceivedVariable;
public void Form1(string AVariable)
{
AreceivedVariable = AVariable;
//do whart ever u want to
}

event that u wnat to do
{
AValue = //the value u want
}

public string Value
{
get{return AValue}
}


//hope this works
Gautham
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now