Click here to Skip to main content
15,913,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a combobox with items {item1,item2,item3...}
Each of these items should fill a groupbox{textbox1,textbox2,textbox3}with different parameters.
My idea is to create a different class {classitem1 classitem2} where to declare all the methods for filling the groupbox with parameters but being a beginner programmer not quite sure about how to do this.
any help please

Copied from Comment
Sorry this is Windows Forms.
The problem for me is how to refer to values of textboxes from the class For example if I create
class 1 
{ 
public void fillGroupBox() 
{ 
//how to refer to form1.txtbox? 
}
Posted
Updated 29-May-11 15:49pm
v2
Comments
Sergey Alexandrovich Kryukov 29-May-11 18:40pm    
Tag it? WPF, Forms, APS.NET, what?!
What seems to be a problem? What did you try? This is right idea, just do it.
--SA
KORCARI 29-May-11 18:54pm    
Sorry this is Windows Forms.
The problem for me is how to refer to values of textboxes from the class
For example if I create

class 1
{
public void fillGroupBox()
{
how to refer to form1.txtbox?


}

hi,

this will help you


C#
<pre lang="cs">
public class MyClass
{

public DataSet GetList(string txt1,string txt2,string txt3)
{

              SqlConnection cs1 = new SqlConnection("Data Source=nemesisfc; Initial Catalog=FreezerTemps; Integrated Security=TRUE");
            SqlCommand cmd1 = new SqlCommand();
            cs1.Open();
            cmd1.CommandText = "write ur sql select query here";
            DataSet dtst = new DataSet();
            SqlDataAdapter dp = new SqlDataAdapter(cmd1);
            dp.Fill(dtst);// for select query

            cs1.Close();
return dtst;
}


}



//---in your form
C#
public void BindDrops()
{
    MyClass cl= new MyClass();
    combobox.DataSource = DTL.GetList(txtbx1.Text,txt2.Text,txt3.Text));
    combobox.DataBind();
}
 
Share this answer
 
public class MyClass
{


    /* For Load Data, Return as a Dataset */
    public DataSet FillData(Pass_your_Values)
    {
// COde for fillup.
    }
.......
.....


And you can bind these dataset or daatable item into combobox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900