public void AddRow(DataGridViewRow dgv_row) { StringBuilder xml_row = new StringBuilder("<row>\r\n"); foreach (DataGridViewCell cell in dgv_row.Cells) { //Colorize string to_append = string.Empty; if (cell.OwningColumn.Name == this.ColoredColumn) { string bcolor = cell.Style.BackColor.A.ToString() + "," + cell.Style.BackColor.R.ToString() + "," + cell.Style.BackColor.G.ToString() + "," + cell.Style.BackColor.B.ToString(); to_append = string.Format("<cell bcolor=\"{0}\">", bcolor); } else { to_append = "<cell>"; } //Add cell value if (cell.ValueType == typeof(bool)) { to_append += (cell.Value != null) ? cell.Value.ToString() : "False"; } else { to_append += (cell.Value != null) ? cell.Value.ToString() : ""; } to_append += "</cell>"; xml_row.AppendLine(to_append); } xml_row.AppendLine("</row>"); Rows.AppendLine(xml_row.ToString()); }