Click here to Skip to main content
15,877,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a combo box and text box in a form.
combobox1 have 3 options,op1,op2 and op3.
based on the combo box value the text in the text box changes,
for ex:
if combobox1_selectedIndex=0
textbox1.text="oooo";
if combobox1_selectedIndex=1
textbox1.text="9999";
the problem is i want to edit the textbox text and repalce the default text with new text.
which means
if combo box selected index is 0,then textbox1.text ="oooo";this i will edit in text box to "oo99".how to acheive this ,please help me.
i am trying to store the textbox text in arrays ar1,ar2,ar3.

What I have tried:

C#
public Form1()
{
    InitializeComponent();
    comboBox1.SelectedIndex = 0;
}
String[] ar1 = new String[32];
String[] ar2 = new String[32];
String[] ar3 = new String[32];

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == 0)
    {
        dt1();
    }
    if (comboBox1.SelectedIndex == 1)
    {
        dt2();
    }
    if (comboBox1.SelectedIndex == 2)
    {
        dt3();
    }
}

void dt1()
{
    textBox1.Text = "0000";
}
void dt2()
{
    textBox1.Text = "9999";
}
void dt3()
{
    textBox1.Text = "aaaa";
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == 0)
    {
        ar1[0] = textBox1.Text;
    }
    if (comboBox1.SelectedIndex == 1)
    {
        ar2[0] = textBox1.Text;
    }
    if (comboBox1.SelectedIndex == 2)
    {
        ar3[0] = textBox1.Text;
    }
}
Posted
Updated 9-Aug-16 0:51am
v2
Comments
Karthik_Mahalingam 9-Aug-16 4:28am    
what is the issue?
Member 12659926 9-Aug-16 4:32am    
seethe form will load with default textbox value,i want to replace the default value with new value.how to make that
Karthik_Mahalingam 9-Aug-16 4:33am    
new value into the combo box selection ?
show the databinding code

1 solution

What I understood from your question is suppose if you made changes to the combo box value and if you try restarting or reloading the form you are getting the old value itself...If that is the issue then you have to save the new value in a file or you can save it in application settings. Then while loading for the first time read from wherever you save it and then display it.

If your question is like when you are changing the index you are getting wrong value then u r function need to be changed,
C#
void dt1()
{
    textBox1.Text = ar[0];
}
void dt2()
{
    textBox1.Text = ar[1];
}
void dt3()
{
    textBox1.Text = ar[2];
}
 
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