Hi how can i add items from 2 listBox to one listBox
ex: listBox1 contain Hello listBox2 contain World! So if button1 is clicked in listbox3 will display Hello World! side bye side but not in a new line like
Hello
World!
private void button2_Click(object sender, EventArgs e)
{
listBox3.Items.Add(listBox1.Items + listBox2.Items);
}
and 1 more how to make HttpWebRequest from 2 listBox.items
private void button1_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create(listBox1.Items + listBox2.Items);
}
ex:
listBox1 contain http://test.com
listBox2 contain /index.html
So if button1 is clicked it will combine items from listBox1 and listBox2 into 1 item
So it will become http://test.com/index.html
and send the request to the website
and 1 more why is this code stop at catch (WebException x)
and why return false; not working when the button1_click is in void, i tried make the button to bool type but it will make the listBox1 error.
private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create(listBox1.Items[i].ToString());
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
if (response.StatusCode == HttpStatusCode.OK)
{
listBox2.Items.Add(listBox1.Items[i]);
}
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
}
catch (WebException x)
{
listBox2.Items.Add("Error! " + x.Message);
}
}
Any help will be much appreciated thanks.