Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Forms

Posted on 2009-04-07
4
Medium Priority
?
207 Views
Last Modified: 2013-12-17
This is probably easy and i am just miss understanding how C# works but here it is anyway.

I have a form. when I leave a combot box I want it to call a child with a drop down options box.
I want to fill the child form with the Data from a query on the first form and this I can do and got to work.  After the item selection is done on the child form I need it to update a differant combo box on the main for and finish wth the original combox_Leave function.  
public void comboBox1_Leave(object sender, EventArgs e)
{
           SqlConnection SpecItem = new SqlConnection(GetItem.MyConn);
            SpecItem.Open();
            DataSet ItemResult = new DataSet();
            SqlCommand Items = new SqlCommand("Select * from Specification where Item_Number ='" + comboBox1.Text + "'", SpecItem);
            Items.CommandType = CommandType.Text;
            SqlDataAdapter ItemAdapter = new SqlDataAdapter(Items);
            ItemAdapter.Fill(ItemResult);
            DataTable Result = ItemResult.Tables[0];
            if (Result.Rows.Count == 1)
            {
                this.comboBox2.Text = Result.Rows[0][4].ToString();
                this.comboBox3.Text = Result.Rows[0][3].ToString();
                this.textBox1.Text = Result.Rows[0][1].ToString();
                this.dateTimePicker1.Value = Convert.ToDateTime(Result.Rows[0][2].ToString());
                this.textBox2.Text = Result.Rows[0][6].ToString();
                this.textBox3.Text = Result.Rows[0][5].ToString();
                this.textBox4.Text = Result.Rows[0][7].ToString();
            }
            else
            {
    //************************************************************************************************************
   // this is where I need the child form to be accessed.  and then allow me toselect the proper 
   //  data from the child form up update comboBox3 on this form
  //***************************************************************************************************************
                for (int i = 0; i < Result.Rows.Count; i++)
                {
                    // Adds the selected items to the combobox
                }
                //updates combobox 3
                comboBox3.Text = Locs.Text;
            }
               DataSet ItemFormula = new DataSet();
               SqlCommand ItemFormulas = new SqlCommand("select Item_Number, Amount from Formulation where Parent_Item='"+comboBox1.Text+"' and Location ='"+comboBox3.Text+"'", SpecItem);
               SqlDataAdapter formulation = new SqlDataAdapter(ItemFormulas);             
               formulation.Fill(ItemFormula);
            bindingSource1.DataSource = ItemFormula;
            bindingSource1.DataMember = ItemFormula.Tables[0].TableName;
            dataGridView1.DataSource = bindingSource1;
            SpecItem.Close();
        }

Open in new window

0
Comment
Question by:Jam9974
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24087719
to be very very frank, i kinda dont like the design of what you are trying to achieve
Leave event - something i dont know will that work
if you have moved the focus on the combobox and then leave do you want to continue with the process or do you want something selected in the combobox before you continue with your process?
0
 

Author Comment

by:Jam9974
ID: 24088091
I want to select an item from the dropdown box before contuning.  Keep in mind I am relatively new to c#
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24088648
if you want to make the selection in the first combobox mandatory then use the selected index changed of the combobox
create 2 comboboxes on the form - c1, c2
by defaul the c2 combobox is disabled
when the value in the c1 combobox changes - if a non default value is selected then you enable the c2 else keep it as disabled

and when the c2 is enabled and the value is selected you can simply reterieve it on the same page
0
 

Accepted Solution

by:
Jam9974 earned 0 total points
ID: 24106379
I figured it at to work as I intended it to by  useing combobox#.SelectedIndexChange += MycreatedFunction;

and MycreatedFunction does
{
     comboBox3.Text = MySelectedLocation.text;
      DataSet ItemFormula = new DataSet();
               SqlCommand ItemFormulas = new SqlCommand("select Item_Number, Amount from Formulation     where Parent_Item='"+comboBox1.Text+"' and Location ='"+comboBox3.Text+"'", SpecItem);
               SqlDataAdapter formulation = new SqlDataAdapter(ItemFormulas);            
               formulation.Fill(ItemFormula);
            bindingSource1.DataSource = ItemFormula;
            bindingSource1.DataMember = ItemFormula.Tables[0].TableName;
            dataGridView1.DataSource = bindingSource1;
}

0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question