Possible Duplicate:
(c# + windows forms) Adding items to listBox in different class
I want to get the combobox value in form1 and use it at form2, because the value will return another data from the registered user
public void povoacboxcliente()
{
List<SM.BancoDados.BD.Model.Clientes> lstClientes = new List<SM.BancoDados.BD.Model.Clientes>();
ClienteFlow flow = new ClienteFlow();
lstClientes = flow.RetornaClientes();
cboxCliente.DataSource = lstClientes;
cboxCliente.DisplayMember = "Nome";
cboxCliente.ValueMember = "Id";
}
Now the value member (Id) will return the sex of the member, that is on database, this part is ok, but what I want is to do the operation in another form.. Here is the code that I’m trying on form2
public void enviasexo()
{
EnviarComando("0238373b3be503");
idClient = Convert.ToInt32(cboxCliente.SelectedValue);
UsuarioFlow usuarioFlow = new UsuarioFlow();
string combo = cboxCliente.SelectedValue.ToString();
string sexo = usuarioFlow.RetornaSexo(combo);
if (sexo == "M")
{
Thread.Sleep(2000);
EnviarComando("0232343b3bdc03");
Thread.Sleep(200); //envia comando
}
else if (sexo == "F")
{
Thread.Sleep(2000);
EnviarComando("0232353b3bdd03");
Thread.Sleep(200);
}
}
the “cboxCliente” was used in form1
Thanks People!
One way is to make the ComboBox public in Form1.Designer.cs
then access the ComboBox from Form2
See similar answer at
Stack Overflow Answer for other similar question