locked
noob question - applying combo box selection to variable RRS feed

  • Question

  • everything my searches have turned up is either more complex
    than i can understand or applies to another language so i thought
    i'd ask this, hopefully not annoyingly simple, question here.

    i've created a form with a series of combo boxes containing values
    from -100 to 100. i can open the box and select a number from
    this list and it appears in the box.

    how do i send that selected number to a variable, say "bright"
    so that i can save it in a text file? the combo box is called "briCtr".

    double clicking the box in the designer window produced this
    code - not sure if i need it:

            private void briCtr_SelectedIndexChanged(object sender, EventArgs e)
            {

            }

    the form is just a series of selection tools that then writes a text
    file with all of the user's selections saved. that text file is then used
    to supply a script with info for variables it needs.

    thanks,
    BabaG
    Thursday, June 28, 2007 7:20 PM

Answers

  • Code Snippet

    public partial class Form1 : Form

    {

    string bright;

    public Form1()

    {

    InitializeComponent();

    this.briCtr.SelectedIndexChanged += new System.EventHandler(this.briCtr_SelectedIndexChanged);

    }

    private void briCtr_SelectedIndexChanged(object sender, EventArgs e)

    {

    bright =(string) briCtr.SelectedItem;

    string path = (System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\test.txt");

    WriteText(bright, path);

    }

    private void WriteText(string text, string path)

    {

    System.IO.FileStream fs;

    System.IO.StreamWriter sw;

    if ((System.IO.File.Exists(path) == true))

    {

    fs = new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write);

    }

    else

    {

    fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);

    }

    sw = new System.IO.StreamWriter(fs);

    sw.WriteLine(System.DateTime.Now.ToString());

    sw.WriteLine("\n");

    sw.WriteLine(text);

    sw.WriteLine("\r\n");

    if (!(sw == null))

    {

    sw.Close();

    }

    if (!(fs == null))

    {

    fs.Close();

    }

    }

    }

     

    Thursday, June 28, 2007 9:40 PM

All replies

  • Code Snippet

    public partial class Form1 : Form

    {

    string bright;

    public Form1()

    {

    InitializeComponent();

    this.briCtr.SelectedIndexChanged += new System.EventHandler(this.briCtr_SelectedIndexChanged);

    }

    private void briCtr_SelectedIndexChanged(object sender, EventArgs e)

    {

    bright =(string) briCtr.SelectedItem;

    string path = (System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\test.txt");

    WriteText(bright, path);

    }

    private void WriteText(string text, string path)

    {

    System.IO.FileStream fs;

    System.IO.StreamWriter sw;

    if ((System.IO.File.Exists(path) == true))

    {

    fs = new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write);

    }

    else

    {

    fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);

    }

    sw = new System.IO.StreamWriter(fs);

    sw.WriteLine(System.DateTime.Now.ToString());

    sw.WriteLine("\n");

    sw.WriteLine(text);

    sw.WriteLine("\r\n");

    if (!(sw == null))

    {

    sw.Close();

    }

    if (!(fs == null))

    {

    fs.Close();

    }

    }

    }

     

    Thursday, June 28, 2007 9:40 PM
  • wow man. thanks!
    Thursday, June 28, 2007 10:04 PM