I am new to c# and I have a trouble: Error CS0120 An object reference is required for the nonstatic field, method, or property In russian it is little bit different: Error CS0120 For non-static field, method, or property is required link to an object.
When I'm closing one form, that downloads some staff and saves it to a .xml files, I should update a combobox on the another form (This form contains a list of recently downloaded files.)
But I have an error. How can I fix it?
The code:
private void Reviews_browser_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Determine if text has changed in the textbox by comparing to original text.
// Display a MsgBox asking the user to save changes or abort.
if (MessageBox.Show("Закрыть, сохранив загруженные БД?", "Внимание!",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = false;
// Call method to save file...
}
else
{
e.Cancel = true;
try
{
string[] dirs = Directory.GetFiles(@Directory.GetCurrentDirectory(), "*.xml");
foreach (string dir in dirs)
{
if (Path.GetFileName(dir) != "HtmlAgilityPack.xml" && Path.GetFileName(dir) != ".xml")
{
int len = Path.GetFileName(dir).Length;
glavnaya.fayly_s_otzivami.Items.Add(Path.GetFileName(dir).Remove(len - 4, 4));
}
}
}
catch (Exception oshibocka)
{
}
}