Click here to Skip to main content
15,920,513 members
Home / Discussions / C#
   

C#

 
AnswerRe: Null reference exception occurs for no reason Pin
OriginalGriff14-Jan-21 6:08
mveOriginalGriff14-Jan-21 6:08 
SuggestionRe: Null reference exception occurs for no reason Pin
Richard Deeming14-Jan-21 6:34
mveRichard Deeming14-Jan-21 6:34 
GeneralRe: Null reference exception occurs for no reason Pin
OriginalGriff14-Jan-21 6:49
mveOriginalGriff14-Jan-21 6:49 
AnswerRe: Null reference exception occurs for no reason Pin
Ralf Meier14-Jan-21 6:37
mveRalf Meier14-Jan-21 6:37 
GeneralRe: Null reference exception occurs for no reason Pin
Alex Dunlop14-Jan-21 6:49
Alex Dunlop14-Jan-21 6:49 
GeneralRe: Null reference exception occurs for no reason Pin
Ralf Meier14-Jan-21 6:51
mveRalf Meier14-Jan-21 6:51 
Questionlearning to code in c# Pin
grumpi_sc30010-Jan-21 20:30
grumpi_sc30010-Jan-21 20:30 
AnswerRe: learning to code in c# Pin
OriginalGriff10-Jan-21 21:01
mveOriginalGriff10-Jan-21 21:01 
AnswerRe: learning to code in c# Pin
Calin Negru10-Jan-21 21:39
Calin Negru10-Jan-21 21:39 
GeneralRe: learning to code in c# Pin
OriginalGriff10-Jan-21 23:11
mveOriginalGriff10-Jan-21 23:11 
GeneralRe: learning to code in c# Pin
Calin Negru11-Jan-21 0:21
Calin Negru11-Jan-21 0:21 
AnswerRe: learning to code in c# Pin
Gerry Schmitz11-Jan-21 5:00
mveGerry Schmitz11-Jan-21 5:00 
AnswerRe: learning to code in c# Pin
BryanFazekas21-Jan-21 5:33
BryanFazekas21-Jan-21 5:33 
QuestionBest release management for winform project Pin
Mou_kol8-Jan-21 5:03
Mou_kol8-Jan-21 5:03 
AnswerRe: Best release management for winform project Pin
Gerry Schmitz8-Jan-21 5:21
mveGerry Schmitz8-Jan-21 5:21 
GeneralRe: Best release management for winform project Pin
OriginalGriff8-Jan-21 8:45
mveOriginalGriff8-Jan-21 8:45 
GeneralRe: Best release management for winform project Pin
Mou_kol8-Jan-21 9:33
Mou_kol8-Jan-21 9:33 
GeneralRe: Best release management for winform project Pin
Mycroft Holmes8-Jan-21 11:37
professionalMycroft Holmes8-Jan-21 11:37 
QuestionHow to save DataGridView cell and text color? Pin
Alex Dunlop7-Jan-21 6:46
Alex Dunlop7-Jan-21 6:46 
AnswerRe: How to save DataGridView cell and text color? Pin
OriginalGriff7-Jan-21 7:49
mveOriginalGriff7-Jan-21 7:49 
GeneralRe: How to save DataGridView cell and text color? Pin
Alex Dunlop7-Jan-21 7:52
Alex Dunlop7-Jan-21 7:52 
GeneralRe: How to save DataGridView cell and text color? Pin
OriginalGriff7-Jan-21 8:22
mveOriginalGriff7-Jan-21 8:22 
GeneralRe: How to save DataGridView cell and text color? Pin
Alex Dunlop12-Jan-21 5:58
Alex Dunlop12-Jan-21 5:58 
I tried to build a Write/Read class as follows:
C#
 class DataGridViewColor
{
    public static void WriteDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
    {
        XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + @"\MyGridColor.xml", null);
        writer.WriteStartDocument();
        writer.WriteStartElement(dgv.Name);
        int LastRow = dgv.Rows.Count-1;
        for (int i = 0; i < LastRow; i++)
        {
            for (int j = 0; j < dgv.Columns.Count - 1; j++)
            {
                writer.WriteStartElement("Color");
                writer.WriteStartElement("CellColor");
                writer.WriteString(dgv.Rows[i].Cells[j].Style.BackColor.ToString());
                writer.WriteEndElement();
                writer.WriteStartElement("TextColor");
                writer.WriteString(dgv.Rows[i].Cells[j].Style.ForeColor.ToString());
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Close();
    }


}

Now, I need to build a class for reading but I don't know how to do that.
Please guide me by giving a code so I can learn something about the solution.
I tried this code but it gives error:
C#
  class DataGridViewColor
{
    public static void ReadDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
    {
        XmlDocument xmldoc = new XmlDocument();
        XmlNodeList xmlnode;
        FileStream fs = new FileStream(Application.StartupPath + @"\MyGridColor.xml", FileMode.Open, FileAccess.Read);
        xmldoc.Load(fs);
        xmlnode = xmldoc.GetElementsByTagName("column");
       for (int i = 0; i <= (xmlnode.Count)/13; i++)
            {
                string cellcolor = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                string textcolor = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
                for (int j = 0; j < 13; j++)
                {
                    dgv.Rows[i].Cells[j].Style = new DataGridViewCellStyle {BackColor = Color.FromName(cellcolor)};
                    dgv.Rows[i].Cells[j].Style = new DataGridViewCellStyle {ForeColor = Color.FromName(textcolor)};
                }
            }
        fs.Close();
    }

}


modified 12-Jan-21 13:12pm.

Questionretrieve the date selected on a calendar control scheduler in C # Pin
Member 150371265-Jan-21 4:14
Member 150371265-Jan-21 4:14 
AnswerRe: retrieve the date selected on a calendar control scheduler in C # Pin
OriginalGriff5-Jan-21 6:44
mveOriginalGriff5-Jan-21 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.