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 ^)
			{
			}
		}

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.