Click here to Skip to main content
15,885,890 members
Home / Discussions / C#
   

C#

 
GeneralRe: change data by using a removable disk Pin
Mycroft Holmes14-Jan-21 11:04
professionalMycroft Holmes14-Jan-21 11:04 
GeneralRe: change data by using a removable disk Pin
Member 1504609315-Jan-21 5:45
Member 1504609315-Jan-21 5:45 
GeneralRe: change data by using a removable disk Pin
Dave Kreskowiak15-Jan-21 6:28
mveDave Kreskowiak15-Jan-21 6:28 
AnswerRe: change data by using a removable disk Pin
Ralf Meier15-Jan-21 9:05
mveRalf Meier15-Jan-21 9:05 
GeneralRe: change data by using a removable disk Pin
Richard Andrew x6418-Jan-21 11:55
professionalRichard Andrew x6418-Jan-21 11:55 
AnswerRe: change data by using a removable disk Pin
Richard MacCutchan14-Jan-21 8:55
mveRichard MacCutchan14-Jan-21 8:55 
AnswerRe: change data by using a removable disk Pin
Gerry Schmitz15-Jan-21 2:26
mveGerry Schmitz15-Jan-21 2:26 
QuestionNull reference exception occurs for no reason Pin
Alex Dunlop14-Jan-21 6:05
Alex Dunlop14-Jan-21 6:05 
Hi,
I use this class to read XML file and get color information of DataGridView rows.
When I run, compiler says: System.NullReferenceException: 'Object reference not set to an instance of an object.'
My class is:
C#
public static void ReadDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
       {
           XmlDocument xmldoc = new XmlDocument();
           XmlNodeList xmlnode;
           FileStream fs = new FileStream(Application.StartupPath + @"\MyGrid.xml", FileMode.Open, FileAccess.Read);
           xmldoc.Load(fs);
           xmlnode = xmldoc.GetElementsByTagName("Row");
               for (int i = 0; i <= dgv.Rows.Count; i++)
               {
                   int cellcolor = int.Parse(xmlnode[i].ChildNodes.Item(0).InnerText.Trim());
                   int textcolor = int.Parse(xmlnode[i].ChildNodes.Item(1).InnerText.Trim());
                   if (cellcolor != 0)
                   {
                       dgv.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(cellcolor));
                       dgv.Rows[i].DefaultCellStyle.ForeColor = Color.FromArgb(Convert.ToInt32(textcolor));
                   }
                   else
                   {
                       dgv.Rows[i].DefaultCellStyle.BackColor = Color.White;
                       dgv.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
                   }
               }
           fs.Close();
       }

My XML file has this structure:
XML
<dataGridView1>
<Row>
<CellColor>-677434</CellColor>
<TextColor>0</TextColor>
</Row>
<Row>
<CellColor>0</CellColor>
<TextColor>0</TextColor>
</Row>
</dataGridView1>

How can I fix it?
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 

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.