I have some problems analyzing a string like textbox, im using code in various forms in the program and its operation is fine, but when they bind the same two lines, here I get a null exception
two lines of intervets
string txbName = "br" + bruker + "txt" + 'B' + o; txtBCont = (TextBox)Controls[txbName];
new information
Greg set me aside to verify that waht is inside the Controls [] array, and this shows what my problem is. It contains only 90 lines of TabControl information.
this is a string
System.Windows.Forms.TabControl, TabPages.Count: 2, TabPages[0]: TabPage: {ShowWeek}
this line is duplicated 90 times when I run this code inside my catch block
catch( System.Exception excep) { System.IO.StreamWriter SW; SW = File.AppendText("C:\\MyDumpFile.txt"); foreach (Control ctrl in Controls) { SW.WriteLine(ctrl); } SW.Close(); }
how could it not be in a Controls array filled with Initialize?
Post post
and this is the full cycle
int dayOfset; int bruker; TextBox txtBCont; for (int i = 0; i < 18; i++) { mysqlCon.Open(); dayOfset = -4; bruker = i + 1; for (int o = 1; o < 6; o++) { MySqlCommand cmd = new MySqlCommand("SELECT (NyeSaker + GamleSaker - (select GamleSaker FROM saker Where Dato = '" + dateTimePicker1.Value.AddDays(dayOfset + 1).ToString("yyyy-MM-dd") + "' AND Bruker_ID = '" + bruker + "' ) ) FROM saker Where Bruker_ID = '" + bruker + "' AND Dato = '" + dateTimePicker1.Value.AddDays(dayOfset).ToString("yyyy-MM-dd") + "'", mysqlCon); string txbName = "br" + bruker + "txt" + 'B' + o; txtBCont = (TextBox)Controls[txbName];
trying to debug it i did it
string txbName = "br" + bruker + "txt" + 'B' + o; txtBCont = br1txtB1; txtBCont = (TextBox)Controls[txbName];
and what happens, it sets txtBCont to the text field on this line txtBCont = br1txtB1; but on elements txtBCont = (TextBox) [txbName]; it returns null again.
Has anyone realized that this is a mistake?