Datagrid Question: How to Highlight Column that has been sorted?

  • Thread starter Thread starter dh
  • Start date Start date
D

dh

I can Highlight A column if I Hardcode the specific cell position
mumber, like below.

private void MyDataGrid_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Cells[3].BackColor = Color.Red;
}
}

My problem is, instead of specifying a cell position of [3], how can I
insert the cell position number of the column that has been sorted?

For example:

e.Item.Cells[SortExpression].BackColor = Color.Red;

Any help is appreciated.
 
There is probably a much simpler way to do this, but the first plan that
comes to mind is to, while processing the sort event, read the sort
expression when it comes in and have that already mapped to a dictionary or
some other accessible mapping method you created from which you can get the
column ordinal number for that sort expression. Set a globally accessible
variable to that number before exiting the sort event handler and then get
that variable and make reference to it while processing the itemdatabound
event.
 
Back
Top