Hi Ben,
My explanation is based on the understanding that the data being
displayed in your datagridview is contained in a dataTable - the
dataTable is the datasource for the datagridview.
When some actions in your code causes a cell to change color - you have
to record/store the row number and column number (or just what field
name) and what color it was changed to - easiest to store in another
dataTable. When you change the sort order of a datagridview the row
numbers of the datagridview change. So you cannot use the datagridview
row numbers (e.RowIndex) and you also cannot use a currencyManager
object because it behave similar to e.RowIndex. You have to identify
the row using the row's Identity field (if your table does not have an
Identity column - you will need one) The way to do this is as follows:
Dim drF() As DataRow = dsMain.Tables("yourTable").Select("rowID = " &
datagridview1.rows(e.rowIndex).Cells("theCellwithRowID").Value)
Then on the datagridview_ColumnHeaderMouseClick event - you have to loop
through all the rows where cell colors have changed (loop through your
other datatable which contains this information) and find each row using
the DataRow array (as above) and programmatically reset each background
color. You have to loop through all the rows in the datagridview and
when a rowID matches - you reset the color for the respective cell.
Once you get the code going - it works pretty smoothly. It isn't that
bad. Just remember that in .Net you are dealing with kind of a lower
level system - meaning you will have to write your own code to make
stuff happen - not as low level as MFC, but not too much higher. So
there aren't as many built in things. You have to build them in
yourself. Afterall, .Net is a programming platform.
Rich
*** Sent via Developersdexhttp://
www.developersdex.com***