StringBuilder sb = new StringBuilder(); foreach(DataGridViewRow row in mainDGV.Rows) { if(row.Cells[0].Value.ToString() == null) { sb.Append(Properties.Settings.Default.userDB[row.Index].ToString(); //this gets the username from a stringCollection using the rowIndex. } } MessageBox.Show(sb.ToString());
StringBuilder sb = new StringBuilder(); foreach(DataGridViewRow row in mainDGV.Rows) { //changed line //Reason:.Tostring() method will throw System.NullReferenceException when it //finds a empty cell. if(!(row.Cells[0].Value is string))//or if( Convert.ToString(row.Cells[0].Value)=="") { sb.Append(Properties.Settings.Default.userDB[row.Index].ToString(); //this gets the username from a stringCollection using the rowIndex. } } MessageBox.Show(sb.ToString());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)