I have this button click code wich is working now:
private void button6_Click(object sender, EventArgs e)
{
using (var w = new StreamWriter(keywords))
{
crawlLocaly1 = new CrawlLocaly();
crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
DialogResult dr = crawlLocaly1.ShowDialog(this);
if (dr == DialogResult.OK)
{
if (LocalyKeyWords.ContainsKey(mainUrl))
{
LocalyKeyWords[mainUrl].Clear();
LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
}
else
{
LocalyKeyWords[mainUrl] = new List<string>();
LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
}
Write(w);
listBox1.Items.Add("Url: " + LocalyKeyWords[mainUrl] + " --- " + "Localy KeyWord: " + crawlLocaly1.getText());
}
if (dr == DialogResult.Cancel)
{
Write(w);
}
}
}
I need that when i make a change either to the mainUrl(key) or to the crawlLocaly1.getText()(the value of the key) so it iwll change in real time also in the ListBox. I tried to do it like this:
listBox1.Items.Add("Url: " + LocalyKeyWords[mainUrl] + " --- " + "Localy KeyWord: " + crawlLocaly1.getText());
But its not showing the key and its vlaue and its adding a new line instead of updating only the value of the key if the key already exist or if the key is not exist in the List to add to the ListBox the new key and its value.
How do i make it so it will update it in real time in the ListBox ?
Ok changed the ListBox line to:
listBox1.Items.Add("Url: " + mainUrl + " --- " + "Localy KeyWord: " + crawlLocaly1.getText());
Now its adding it good but its adding it as a new line. I want that it will add it and replace the line that already the mainUrl exist in the ListBox.
And if the mainUrl is not exist in the ListBox then add it with its value in a new line.
But all the time if the Key(mainUrl) exist in the ListBox replace it or change only the value(crawlLocaly1.getText() ) .
To correct the line
when you write
LocalyKeyWords[mainUrl]you get aList<string>object. So when you concat this List to string, you actually call to the methodList<string>.ToString().Try to use this line insted:
For the real time problem
To edit the line in real time you need to remove the previous line before, like that
Just for you know, to work with data that contains a two or more variables. Its better to use the
ListViewcontrol. This control know how to work like list, and it can split the data to columns.See ListView in msdn.