winforms - visual studio c# DataGridView maintain background color after sort -
i populated datagridview datatable contains plain text. later, set specific cell's background color using:
grid.rows[row].cells[col].style.backcolor = setcolor;
this works fine until click on column sort button in datagridview. know if there way maintain background color after sorting, irrespective of text value of cell. 1 time set cell's background color, remember background color after sorting.
i have seen other examples using
cellformatting(object sender, system.windows.forms.datagridviewcellformattingeventargs e)
event handler, code write here seems have preconceived notion of color cell's background needs in relation cell's text content (ex: if celltext == "critical" ...). not work in case, need remember cells set specific color.
any help?
here had (thanks pointers sinatr) : had create sec datatable used solely maintain track of cells colors. then, had add together hidden column datagridview used key. set row number of datatable in field after gets sorted, can utilize row-number key determine row index color table. added code in datagridview's cellformatting check color table , reapply color formatting. create matters little more complicated, having issues on getting 1st column become invisible, had ensure hidden column not first column.
overall sense these steps hacks around poorly designed , buggy datagridview. can't imagine scenario want color cell, , have revert colors after sorting. sorting, in mind, rearrangement, not changing properties or values. i'm sure datagridview great , flexible many application, seems fundamental bug or design flaw.
c# winforms datagridview datatable
No comments:
Post a Comment