binteron 0 Newbie Poster

I have a simple database that displays information in various datagridview controls on the same form. One thing I would like to do is change the colour of a row if the value from a cell returns "poor", or "fair"

I call a private function to go through each row in the datagrid just after it is connected to the bingingSource. I can get it to change the colour, but it formats all the rows with that colour, and I want only the row that returned the value to be changed.

private void checkForSurveyColour()
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            try
            {
                CNumColour = dataGridView1.CurrentRow.Cells["RepVisits"].FormattedValue.ToString();
                if (CNumColour != null)
                {
                    foreach(DataGridViewCell cells in row.Cells)
                    {
                        if (CNumColour == "Fair")
                        {
                            cells.Style.ForeColor = Color.Pink;
                        }
                        else if (CNumColour == "Poor")
                        {
                            cells.Style.ForeColor = Color.Red;
                        }
                    }
                }


            }
            catch(System.Exception ex)
            {

            }
        }
                    
      
    }

Thanks.

binteron 0 Newbie Poster

I figured out my problem. I had included the database file in the project. Therefore it was overwritten each time I compiled the project, making it look like the database wasn't being updated. I created an external database and it works flawlessly now.
Thanks for the responses.

binteron 0 Newbie Poster

This is the exact problem I am having. Autogenerated code with DataGridView control doesn't save data to the table? Help please if you can.

binteron 0 Newbie Poster

I see, so in essence i created an extra pointer, one that wasn't needed. I had wondered about that, I must have misinterpreted the first book i read. Thanks a bunch for taking the time to clear that up form me.

Cheers Salem.

binteron 0 Newbie Poster

Well, I moved the delete [] catalogue line to the end of the program and now the thing runs perfectly.

Thanks Salem! I new it would be something simple and painfully obvious when you look at it.....duhhh.

best regards

binteron 0 Newbie Poster

Hi Salem, Thanks for the quick reply. *ptr is something from a different book, it said pointer was best way to access dynamic arrays.

I have run the program many times and not entered a space after the number of cars, so that's a good thought, but not it. Also I had put a cin.get() after the input to see if there was something there causing the problem.

binteron 0 Newbie Poster

I am new to C++ and working through SAMS C++ primer. one of the excercies involves creating a dynamic array of structures to catalogue car information. I have the following code almost working and I am sure that I am missing something really simple.

The program compiles and runs as expected, however on the first run through the loop, the "make" of the car is not stored in the array. All subsequent loops capture the input and display properly.

Any help or point in the right direction would be appreciated.

thanks.

//c++ primer ch 5 ex 6.
#include <iostream>
using namespace std;

struct car {

    char make[20];
    int year;

    
};
int c;
int t = 1;
    int main() {
            cout <<"How many cars would you like to catalogue? ";
            cin >>c;
            cin.get();

            car * catalogue = new car[c];
            car *ptr = &catalogue[0];

            for (int i = 0;i < c; ++i)
            {                 
                cout <<"Car# "<<t<<":\n";
                cout <<"Enter make of car: ";
                cin.getline(ptr[i].make,20);
                cout <<"Enter year of car: ";
                cin >> ptr[i].year;
                cin.get();
                cout <<"\n";            
            ++t;
            };
            delete [] catalogue;

            cout <<"Your catalogue of cars: \n";
            for (int i = 0; i < c;++i)
            { cout <<catalogue[i].year<<" "<<catalogue[i].make<<"\n";
            };

    }