Adding Data to datagridview [modified]
-
do { iniText = iniStream.ReadLine(); // Skip comments started by \* character if(String.Compare(iniText.Substring(0,1),("\*")) == 0) continue; string \[\] dataItems = iniText.Split(new Char \[\] {','}); dataGridView1.Rows.Add(dataItems); } while (iniText != null);
When stepping through the code, dataItems correctly contains each array of comma separated variables, but the datagrid control is not being populated with the Rows.Add method. What am I missing? t.i.a OK, I changed it to this
do { iniText = iniStream.ReadLine(); if (iniText == null) continue; // Skip comments started by \* character if(String.Compare(iniText.Substring(0,1),("\*")) == 0) continue; string \[\] dataItems = iniText.Split(new Char \[\] {','}); dataGridView1.Rows.Add(dataItems); } while (iniText != null);
obviously I need to rethink my loop logic. But when i step through in Debug with F5 it populates the control properly, when I run without debugging, it is still empty. Why does that happen?
modified on Wednesday, October 14, 2009 2:42 AM
-
do { iniText = iniStream.ReadLine(); // Skip comments started by \* character if(String.Compare(iniText.Substring(0,1),("\*")) == 0) continue; string \[\] dataItems = iniText.Split(new Char \[\] {','}); dataGridView1.Rows.Add(dataItems); } while (iniText != null);
When stepping through the code, dataItems correctly contains each array of comma separated variables, but the datagrid control is not being populated with the Rows.Add method. What am I missing? t.i.a OK, I changed it to this
do { iniText = iniStream.ReadLine(); if (iniText == null) continue; // Skip comments started by \* character if(String.Compare(iniText.Substring(0,1),("\*")) == 0) continue; string \[\] dataItems = iniText.Split(new Char \[\] {','}); dataGridView1.Rows.Add(dataItems); } while (iniText != null);
obviously I need to rethink my loop logic. But when i step through in Debug with F5 it populates the control properly, when I run without debugging, it is still empty. Why does that happen?
modified on Wednesday, October 14, 2009 2:42 AM
I agree your loop logic needs some work, but in both original form and the modified form below it works fine either debugged or run as release version. Without seeing the rest of your code, I can only assume the difference is path related - is the file you are reading relative to the debug code folder and thus not available in the release version?
string\[\] lines = File.ReadAllLines(@"C:\\XXTemp\\new.txt"); foreach (string line in lines) { if (!line.StartsWith("\*")) { // Not a comment - they start with \* dataGridView1.Rows.Add(line.Split(',')); } }
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
I agree your loop logic needs some work, but in both original form and the modified form below it works fine either debugged or run as release version. Without seeing the rest of your code, I can only assume the difference is path related - is the file you are reading relative to the debug code folder and thus not available in the release version?
string\[\] lines = File.ReadAllLines(@"C:\\XXTemp\\new.txt"); foreach (string line in lines) { if (!line.StartsWith("\*")) { // Not a comment - they start with \* dataGridView1.Rows.Add(line.Split(',')); } }
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
Thanks. Of course, that is exactly what it was, I hadn't changed the file read section to allow the user to browse for an actual file location! doh! thanks for the heads up