Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Data

Status
Not open for further replies.

JamesHanley

Programmer
Jun 16, 2006
57
US
I am trying to Pass whatever is selected in cboApps from Form1.cs(gui) to SLAFunctions.cs(code only).

Whatever is selected in drop down menu needs to be passed to another form, how do i do this?

Please..
 
Just remove this line:

public string textcombo;

from SLAFunctions.cs, it isn't needed any more

and as you probably have already done from what you just said, move the code in button1's click handler to cboApps's SelectedIndexChanged handler


Hope this helps.

[vampire][bat]
 
Well on form one i need to set a variable like

textcombo = cboApps.Text

but whenever i type something with cboApps.Text it has no idea what it is, or wher eit is comming from that is the problem i am running into.
 
In doing so it will allow me to add another colum to my data grid.
 
I'm not sure that I understand what the problem is. I've created:

Form1 with just a single combobox (cboApps)
Class1 with a simple method

as follows:

Code:
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private Class1 class1;
		private string ComboText;  //if needed in form declare it here

		private void cboApps_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			ComboText = cboApps.Text; //if needed in form assign it here
			class1 = new Class1() ;
			//if using ComboText variable
			class1.StringFromForm1(ComboText);
			//otherwise use the following line
			//class1.StringFromForm1(cboApps.Text);
		}

Code:
using System;

namespace WindowsApplication7CSharp
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class Class1
	{
		public Class1()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		//if required in class declare it here
		private string ComboText;

		public void StringFromForm1(string s)
		{
			//if using ComboText in the class assign it here
			ComboText = s;
			//do something with the value
			//if using ComboText here then
			System.Windows.Forms.MessageBox.Show(ComboText);
			//otherwise use the parameter directly
			//System.Windows.Forms.MessageBox.Show(s);
		}
	}
}

I've populated the combobox with a few strings:
Item 1
Item 2
Item 3
Item 4


As soon as I've selected an item from the combobox, a messagebox appears showing me the text.

I hope this explains things better for you.

[vampire][bat]
 
Going back to your first post:
I am trying to Pass whatever is selected in cboApps from Form1.cs(gui) to SLAFunctions.cs(code only).

Your code (files you posted) does exactly what you were expecting (see in blue).

Code:
public void cboApps_SelectedIndexChanged(object sender, System.EventArgs e)
{
	[COLOR=blue][b]sla.textcombo = cboApps.Text; [/b][/color]
	return;{} 
}

private void button1_Click(object sender, System.EventArgs e)
{
	MessageBox.Show("This May Take A Few Moments. Thank You.");
	DataSet lstDataSet = new DataSet();
	[COLOR=blue][b]sla.HRDataSet(lstDataSet, cboApps.Text);[/b][/color]
	dataGrid1.DataSource = lstDataSet.Tables[0];
}
Though textcombo was never used anywhere in SLAFunctions.cs, but SLAFunctions.textcombo is kept there maybe for some other purpose (maybe related to below).

Now, what you said here bugs me a bit...
Whatever is selected in drop down menu needs to be passed to another form, how do i do this?
You mean another form other than Form1? If so, then this is were SLAFunctions.textcombo will play its part. You pass the SLAFunctions instance to that, or any form, then they access textcombo's value, as if indirectly accessing cboApps.text.
eg..
Code:
public class Form2 : System.Windows......
{
    public SLAFunctions sla;
    
    private void Form_Load(...)
    {
        [COLOR=red][b]string grp = sla.textcombo;[/b][/color]
    }
}
I hope I, too, understood what you are really askin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top