{"id":1493,"date":"2018-07-27T09:39:31","date_gmt":"2018-07-27T09:39:31","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=1493"},"modified":"2022-02-17T06:24:02","modified_gmt":"2022-02-17T06:24:02","slug":"styling-cells-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/datagridview\/styling\/styling-cells-2","title":{"rendered":"Styling Cells"},"content":{"rendered":"<p>\n<em><strong>NOTE<br \/>\nIf you have just set the datasource of a datatableview&nbsp;any styling you apply to cells may get ignored.&nbsp; You need to set your styling in (or wait for)&nbsp;dataGridView1_DataBindingComplete() instead.<\/strong><\/em>\n<\/p>\n<h4>\nStyling cells<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\t\/\/********************************************************\r\n\t\t\/\/********************************************************\r\n\t\t\/\/********** DATAGRIDVIEW DATA BINDING COMPLETE **********\r\n\t\t\/\/********************************************************\r\n\t\t\/\/********************************************************\r\n\t\tprivate: System::Void dataGridView1_DataBindingComplete(System::Object^  sender, System::Windows::Forms::DataGridViewBindingCompleteEventArgs^  e) \r\n\t\t{\r\n\t\t\tint RowIndex;\r\n\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\t\/\/------------------------------------------------------\r\n\t\t\t\t\/\/----- APPLY FORMATTING TO ANY CELLS REQUIRING IT -----\r\n\t\t\t\t\/\/------------------------------------------------------\r\n\t\t\t\t\/\/Done in dataGridView1_DataBindingComplete() event as otherwise will be ignored\r\n\r\n\t\t\t\tRowIndex = 0;\r\n\t\t\t\tfor each(DataGridViewRow ^NextRow in dataGridView1-&gt;Rows)\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/----- SET RESULT COLOUR -----\r\n\t\t\t\t\tif (ColumnIndex_Result &gt; -1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (NextRow-&gt;Cells[10]-&gt;Value-&gt;ToString() == &quot;Pass&quot;)\r\n\t\t\t\t\t\t\tNextRow-&gt;Cells[10]-&gt;Style-&gt;ForeColor = System::Drawing::Color::Green;\r\n\t\t\t\t\t\telse if (NextRow-&gt;Cells[10]-&gt;Value-&gt;ToString() == &quot;Fail&quot;)\r\n\t\t\t\t\t\t\tNextRow-&gt;Cells[10]-&gt;Style-&gt;ForeColor = System::Drawing::Color::Red;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tRowIndex++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tcatch (Exception ^)\r\n\t\t\t{\r\n\t\t\t}\r\n\t\t}\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NOTE If you have just set the datasource of a datatableview&nbsp;any styling you apply to cells may get ignored.&nbsp; You need to set your styling in (or wait for)&nbsp;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 { \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; \/\/&#8212;&#8211; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118],"tags":[],"class_list":["post-1493","post","type-post","status-publish","format-standard","hentry","category-styling"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=1493"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1493\/revisions"}],"predecessor-version":[{"id":1495,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/1493\/revisions\/1495"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=1493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=1493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}