Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have combox with 4 values Apple,Oranges,Kiwi and Bread on windows form. I want to update a code in textbox on same form based on value selected in combobox. so if Apple got selected in combobox, code app should show if kiwi in combobox than value in text box is kiw and so on.

I have kept all data in combo box i have not create any data for this.

1. Do i have to create Sql Data for this and then i have to do the connection?

please friends i don't have only 4 item i have data more the 30 so please let me know how i manage this data in combo box


==================================================================

On the click to the add button the text box should display the code which i have written it gives me error

private void button2_Click(object sender, EventArgs e)
       {
           frmsalesorderbooking f2 = new frmsalesorderbooking();
           groupBox1 gb = new GroupBox1();
           int topPosition = 5;
           for (int j = 0; j < Convert.ToInt32(textBox6.Text.ToString()); j++)
           {
               comboBox2 cb = new ComboBox1();
               cb.left = 5;
               cb.top = topPosition;
               topPosition += 30;
               gb.controls.Add(cb);
           }
           frmsalesorderbooking.Control.Add(gb);
           frmsalesorderbooking.show();
       }





Thanks in Advance :rose::rose:
Posted
Updated 17-Oct-10 22:35pm
v5

There is no Need for SQL Data and SQL Connection for this Query you can solve your problem very easly by this way

Add Data Apple,Oranges,Kiwi and Bread your Combobox and then write the
given code in SelectedIndexChanged Event of Combobox.

C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
     {
         textBox1.Text = comboBox1.Text;
     }
 
Share this answer
 
Comments
aayu 18-Oct-10 3:30am    
ok well your ans is helpful thank you very much
But i want to ask that i have create one master page of product and sub product ok and i want that from master page data should come on the sales order combo box and on selection of values from combo it should display in text box.
Dalek Dave 18-Oct-10 3:53am    
Good Answer.
Try this code It's Quite EASY.

Or you want something else??

VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "RED" Then
            TextBox1.Text = "RED SELECTED"
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("RED")
    End Sub


:cool::cool::cool::cool::cool::cool:
 
Share this answer
 
Comments
Dalek Dave 18-Oct-10 3:53am    
Good Call.
Be Yourself 18-Oct-10 9:58am    
Thanxxx.
hope this is what u want!

in master page's window loaded sub:

private sub Window1_loaded(..........)
combobox1.items.add("Apple")
combobox1.items.add("Kiwi")
.
.
end sub

then create another function to load these items.. i will use a list here coz u may hav more than 30 items..

public function AddInList() as List(of String)

dim lst as list(of string)

for i=0 to combobox1.items.count
lst.add(combobox1.items(i))
next i

return lst

end function

Now in your sub-product page:

do this in that sub-product's loaded sub:

dim w as window1
dim myList as List(of string)=w.AddInList()

and then

for i as integer=0 to myList.count
combobox2.items.add(myList(i).toString())
next i

textbox2.text=combobox2.selectedItem()


Hope this helps!! :)
 
Share this answer
 
Comments
aayu 18-Oct-10 8:53am    
nope not this way :(
Tarun.K.S 18-Oct-10 8:56am    
:o well aarti u hav to elaborate more on what you want..Its still unclear! just post atleast a screenshot or giv us some code so that we can help you!
Tarun.K.S 18-Oct-10 9:02am    
well my code was in visual basic..
http://www.developerfusion.com/tools/convert/csharp-to-vb/

u can check this site..u can convert vb to c# and vice-versa!

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