Question: 1. Assume that we want to write the code for the following. If the user types a string into the text portion of a combo

1. Assume that we want to write the code for the following. If the user types a string into the text portion of a combo box named cboNames then as soon as the user types the return key ( key) the program should add that name to the Items list and remove the string from the Text property. How would you finish this method to do so?

private void cboNames_KeyPress(object sender, KeyPressEventArgs e)

{

}

the code below is my guess, is this right?:

private void cboNames_KeyPress(object sender, KeyPressEventArgs e)

{

cboNames.Text = cboNames.Text.Trim();

cboNames.Items.Add(cboNames.Text);

cboNames.Text = String.Empty;

}

My other question is:

2. Write instructions that will do the following. It will open an output file with the directory name options.txt. It will write each of the items in a list box named lstOptions onto the output file as a line. When the last item is written, close the file.

Here's what i think it should the code should look like:

StreamWriter outputFile;

string theName

outputFile=File.CreateText(options.txt);

while (!outputfile.EndOfStream)

{

theName = outputFile.WriteLine();

lstOptions.Items.Add(theName);

}

namesFile.Close();

The questions are related to C#

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!