I have a problem with the combobox.SelectedIndex function. The problem is that in void and static void it just returns a -1. Now before anyone comes and says if there is anything in it at all, yes it is, I've debugged the code and found that it only returns a -1 in static void and void , now I'm curious as to why it doesn't work, actually a very simple code.
void writecombo()
{
int CURRENT_LOG = combo.SelectedIndex; //< -1
Globals.LG[CURRENT_LOG] += "Hello!" + Environment.NewLine; //Crash, because it is -1
...
}
Where it works:
private void textbox1_KeyDown(object sender, KeyEventArgs e)
{
if (GetAsyncKeyState(Keys.Enter) < 0)
{
int CURRENT_LOG = combo.SelectedIndex; // Not Null
Globals.LG[CURRENT_LOG] += "Hello!" + Environment.NewLine;
...
}
}
I would be happy to get help and also if someone could explain to me why this is the case :)
EDIT: The problem only comes when I want to access this void from a static void, I wanted to use it to access the objects in form1 in a static. (var from = new Form1) MRE