MrTV
asked on
C# Add to listbox
the code below it add only one line to list box how can I correct to make it insert for all text
private void button1_Click(object sender, EventArgs e)
{
string url = "http://www.presscouncil.or.th/th2/index.php?option=com_content&view=article&id=230&Itemid=100084";
string result = null;
try
{
WebClient client = new WebClient();
result = client.DownloadString(url);
listBox1.Items.Add(result);
}
catch (Exception ex)
{
// handle error
MessageBox.Show(ex.Message);
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From what I can make out your result data is stored in a single string. you will need to split the string into an array, or loop your webclient call to fetch more results.
Hi, use this code
private void textBox_Leave(object sender, System.EventArgs e)
{
listBox1.Items.Add(((TextB ox)sender) .Text);
}
private void textBox_Leave(object sender, System.EventArgs e)
{
listBox1.Items.Add(((TextB
}
try using this code :
Above code will add all the content line by line.
private void button1_Click(object sender, EventArgs e)
{
string url = "http://www.presscouncil.or.th/th2/index.php?option=com_content&view=article&id=230&Itemid=100084";
string result = null;
try
{
WebClient client = new WebClient();
result = client.DownloadString(url);
string[] lines = result.Split(new string[]{"\n"},StringSplitOptions.RemoveEmptyEntires);
foreach(string line in lines)
{
listBox1.Items.Add(line);
}
}
catch (Exception ex)
{
// handle error
MessageBox.Show(ex.Message);
}
}
Above code will add all the content line by line.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I can understand the comment accepted.
The assist of mkobrin says in different words what I said, so I am surprised that gets an assist but my comment doesn't.
Of what use is the comment by samirbhogayta in resolving your problem?
The assist of mkobrin says in different words what I said, so I am surprised that gets an assist but my comment doesn't.
Of what use is the comment by samirbhogayta in resolving your problem?
I agree with Andy.. :)