We have two situations where we are modifying cell content and/or properties, and not getting the result we are looking for, as follows:
1. We want to be able to selectively hide and/or show grid columns (after the grid has been initialized) on auto fit grids. Our existing logic works fine - it sets the widths properly and the grid auto-sizes correctly. The problem is that the formerly hidden column is displayed with a grey (disabled) color. I can change the ForeColor and ForeColorDisabled properties to black, but then the cell contents will be also be black on the highlighted row. How can we revert the row to normal fore colors?
2. We want to display buttons in a grid column only on certain rows, and have the button cell be blank on the other rows. So I have defined the button column initially with style = Default, and then change it to Button when I load the image. But my routine is not working - the buttons do not appear at all - how should this be fixed?
public static void SetGridCellImage(UltraGridRow row, string columnName, object image = null)
{
try
if (row != null && !string.IsNullOrWhiteSpace(columnName))
UltraGridCell cell = row.Cells[columnName];
if (cell != null)
cell.Column.Style = (image == null)
? Infragistics.Win.UltraWinGrid.ColumnStyle.Default : Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
cell.ButtonAppearance.Image = image;
}
catch
Hello Richard,
Thank you for posting in our forum.
Please find bellow the answers to your questions:
1. I followed the steps you suggested and was unable to reproduce the behavior you're describing. I have attached the sample project I used to test this. Please in order to be able to further investigate can you please give me more information about: how exactly you are hiding the columns; how you display back the hidden columns; how you have set the AutoFitStyle property of your Grid; how you set the columns width. It will help if you can send me a small isolated sample solution.
2. In your SetGridCellImage method you are actually set the Column style here cell.Column.Style. In order to set the cell style you need to change your code like this:
cell.Style = (image == null) ?
Infragistics.Win.UltraWinGrid.ColumnStyle.Default :
nfragistics.Win.UltraWinGrid.ColumnStyle.Button;
Please check attached sample solution where I have implement this approach.
Waiting for your feedback.
Thank you for using Infragistics Controls
The code you sent for issue #2 above fixed our problem - thank you.
In regard to #1 above, here is the routine we are using. It will be somewhat confusing to you because we have done a lot of engineering for your grid control to simplify and centralize almost all grid operations. We have developed GridSchema, GridBand, and GridColumn classes which encapsulate all of the necessary properties for a grid, and are used to initialize and handle all of grid operations we perform.
When we define the columns for a grid, setting the column width to zero causes our logic to set the Hidden flag on the column. So calling the routine below with a zero width will hide the column, and a non-zero width will unhide the column and set the width accordingly.
public static void SetGridColumnWidth(UltraGrid grid, int bandNo, string columnName, int width = 0) { try { if (grid != null && bandNo >= 0 && bandNo < grid.DisplayLayout.Bands.Count && !string.IsNullOrWhiteSpace(columnName)) { GridSchema gridSchema = GetGridSchema(grid); if (bandNo < gridSchema.Bands.Count) { GridBand gridBand = gridSchema.Bands[bandNo]; foreach (GridColumn gridColumn in gridBand.GridColumns) { UltraGridColumn column = grid.DisplayLayout.Bands[bandNo].Columns[gridColumn.Key]; if (column != null) { if (column.Key != columnName) column.Width = gridColumn.Width; else { column.Hidden = (width <= 0) ? true : false; column.Width = (width <= 0) ? 0 : width; gridColumn.Hidden = column.Hidden; gridColumn.Width = column.Width; if (!column.Hidden) {
// The line below doesn't work //column.CellAppearance.ResetForeColor();
// The lines below set the fore color from gry to black on a formerly hidden column, but then fore color stays black when the row is highlighted //column.CellAppearance.ForeColorDisabled = System.Drawing.Color.Black; //column.CellAppearance.ForeColor = System.Drawing.Color.Black; } } } } } } } catch { } }
One more point I should make: as you will see, the above routine restores the original width on all columns other than the selected one. This is necessary for grids in which the AutoFitStyle = ResizeAllColumns, and most of our grids are defined in that manner. The logic works correctly, and grids will resize according to the latest column width settings.
Thank you for your feedback.
Can you please check in your wrapper class if you set the hidden column Activation property to Disabled, or if you set the column CellAppearance? If you do so you need to set back either the Activation or CellAppearance to appropriate to your scenario values.
If this not the case, I will need a sample solution in order to be able to investigate this in deeper details.
I am waiting for your feedback.
We are still following this forum thread.
Please feel free to let us know if you still have any questions on this matter.