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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started