NOTE
If you have just set the datasource of a datatableview any styling you apply to cells may get ignored.  You need to set your styling in (or wait for) dataGridView1_DataBindingComplete() instead.

Styling cells


		//********************************************************
		//********************************************************
		//********** DATAGRIDVIEW DATA BINDING COMPLETE **********
		//********************************************************
		//********************************************************
		private: System::Void dataGridView1_DataBindingComplete(System::Object^  sender, System::Windows::Forms::DataGridViewBindingCompleteEventArgs^  e) 
		{
			int RowIndex;

			try
			{
				//------------------------------------------------------
				//----- APPLY FORMATTING TO ANY CELLS REQUIRING IT -----
				//------------------------------------------------------
				//Done in dataGridView1_DataBindingComplete() event as otherwise will be ignored

				RowIndex = 0;
				for each(DataGridViewRow ^NextRow in dataGridView1->Rows)
				{
					//----- SET RESULT COLOUR -----
					if (ColumnIndex_Result > -1)
					{
						if (NextRow->Cells[10]->Value->ToString() == "Pass")
							NextRow->Cells[10]->Style->ForeColor = System::Drawing::Color::Green;
						else if (NextRow->Cells[10]->Value->ToString() == "Fail")
							NextRow->Cells[10]->Style->ForeColor = System::Drawing::Color::Red;
					}

					RowIndex++;
				}
			}
			catch (Exception ^)
			{
			}
		}

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.