How do I higlight a specific column in UltraWinGrid for forms? My requirement is, I search for a column in the grid, if the column is found then higlight it.
Thanks,
Vijayan
Thanks Mike. That's exactly what I wanted. Appreciate your help.
Hi Vijayan,
It sounds like when you say "highlight" you mean that you want to select the column. That's what happens when the user clicks on a column header. To programmatically select a column, you would do something like this:
UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns["My Column"]; this.ultraGrid1.Selected.Columns.Add(column.Header);
Vijayan,
If I understand you correctly you want to activate a cell and then have the background color of the entire column that contains the cell change its color.
You could handle the AfterCellActivate event and insert code like this:
ultraGrid1.DisplayLayout.Bands[0].Columns[ultraGrid1.ActiveCell.Column.Index].CellAppearance.BackColor = Color.Yellow;
Then handle the BeforeCellDeactivate event and include code like this:
ultraGrid1.DisplayLayout.Bands[0].Columns[ultraGrid1.ActiveCell.Column.Index].CellAppearance.BackColor = Color.White;ultraGrid1.DisplayLayout.Bands[0].Columns[ultraGrid1.ActiveCell.Column.Index].CellAppearance.ForeColor = Color.Black;
Of course, you will set the colors back to whatever you had before the column was highlighted. I was using BackColor white and ForeColor black.
Let me know if that gives you what you want.
Michael S.
Michael,
Thanks for the reply. I tried, but this is highlighting the column but the column color stays the same.
Is there a way that the focus or the column is higlighted and when I select a cell or navigate away the column looks similar to other columns. Similat to what happens when we click on the column header, the whole column is higlighted.
In the InitializeLayout event you can set the BackColor of the CellAppearance property of the column like so:
e.Layout.Bands[0].Columns["FirstAmount"].CellAppearance.BackColor = Color.Yellow;
If you want to do it later after the grid has already been rendered on the Form, say in a Button_Click event, you could do something like this:
foreach (UltraGridColumn col in ultraGrid1.DisplayLayout.Bands[0].Columns) { if (col.Key == "SecondAmount") { col.CellAppearance.BackColor = Color.Tomato; } }
Try that and let me know if it works for you.