0

I am trying to Heat map data for quick viewing, and faster analytics. however I have tried several different was to call upon my dependency. When I run the program I get the error, "object not an instance of an object. My program quickly changes between different data sets from a combobox. so i must add in condition for the selected combobox item, so i can read the correct column, as the column has the same name but always at the end of the dataset. Here is the coding I have right now.

public void heatmap()
    {
        string selected = comboBox1.SelectedItem.ToString();
        if (selected == "General")
        {
            for(int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                int val = Int32.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());                 
                //No Change
                if (val == 0)
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.WhiteSmoke;
                }
                //Big Drop
                else if (val == 1)
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Navy;

                }
                // Slight Drop
                else if (val == 2)
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
                }

                // Slight Raise
                else if (val == 3)
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.OrangeRed;
                }

                // Big Raise
                else if (val == 4)
                {
                    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
                }

is there another way to call upon the row, column cell value?? any help is appriciated!! this data set displays the columns in this order. Name, Price, Heat.

Michael Smith
  • 77
  • 1
  • 10
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Sinatr Oct 04 '17 at 12:15
  • thank you i will double check the database, It should be set to allow no nulls, default value of row data should be set to 0. meaning that there should be no nulls, just a 0 if it has not been updated yet or changed by background worker. – Michael Smith Oct 04 '17 at 12:24
  • Often this error comes from having an emtpy row; try to set `AllowUserToAddRows` to false! ((Btw, you may want to check out [these post](https://stackoverflow.com/search?q=user%3A3152130+heatmap), two of which show heatmaps in a dgv..)) – TaW Oct 04 '17 at 12:33
  • Upon checking the database setup, it was allowing nulls in the column i was trying to read. I removed that option. But still getting the same error. There is 2500+ rows. I have it set to allow no nulls what so ever. – Michael Smith Oct 04 '17 at 13:02
  • @TaW thank you for the recommendations. The issue isn't with the calling of the colors or setting the colors, As by the way im calling the colors the system reads the color codes automatically. I am watching a couple of videos on the referenced error code and possible fixes. I do not have the users to allow user to add row, as the database if a fixed reference. In essence the database is truely a list of things to check through api connection. Calling from name column and the rest of the columns are place holders for grabbed information during calculations, and graphing. – Michael Smith Oct 04 '17 at 13:08
  • continued. After doing so heat column will be updated, current price updated. all other information cleared to save storage on Harddrive. As it takes less that 1 sec, to grab, parse, and insert into database. the information needed. – Michael Smith Oct 04 '17 at 13:10

1 Answers1

0

So I fixed the problem My heatmap class was outside the main datagridview class which is private. By placing the same code inside this coding. It fixed the error. I will guess this is due to the datagridview class being private and not public. But not sure. I am no longer recieving this error and the colors show properly.

Thank you all for the reply's and answers. They actually put me on the right path to fixing the issue.

Michael Smith
  • 77
  • 1
  • 10