Posted 30 March 2025, 12:59 am EST
I need to show the images in the cell on specific conditions, Is there any alternative to SetCellImage?
Forums Home / ComponentOne / WPF Edition
Posted by: david on 30 March 2025, 12:59 am EST
Posted 30 March 2025, 12:59 am EST
I need to show the images in the cell on specific conditions, Is there any alternative to SetCellImage?
Posted 31 March 2025, 5:53 am EST
Hi David,
To show images in specific cells of a column, you can inherit the CellFactory class to create your custom cell factory and override its CreateCellContent method. In the method, you can check for your specific conditions and set the image to the cell.
See the attached sample project for reference - ImageConditional.zip
Best Regards,
Kartik
Posted 1 April 2025, 9:13 am EST
Hi Kartik
I am using Flexgrid, not c1flexgrid.
The grid is unbound.
I have several columns, My requirement for setting Image is not specific to certain columns.
I need to set some alert Image next to the text for specific cells only depending on conditions.
Can you please give me another example?
Thanks and Regards
David
Posted 2 April 2025, 6:42 am EST
Hi David,
>> I am using Flexgrid, not c1flexgrid.
We have converted the project to use the FlexGrid control (.NET 8).
>> The grid is unbound.
Our sample already uses the grid in unbound mode, and manually adds rows and data into the grid.
>> I need to set some alert Image next to the text for specific cells only depending on conditions.
To display text and image in the same cell, you need to create a custom CellTemplate using a TextBlock and an Image. Then, use the CreateCellContent method to set the text and image dynamically at runtime.
Please refer to the updated sample project for reference - ImageConditional_Updated.zip
In case you still face any issues, please update this project to show your implementation and the issue you are facing, so we can investigate further and assist you better.
Best Regards,
Kartik
Posted 18 June 2025, 8:14 am EST
Hi Kartik,
Can you please check what is wrong with this cellfactory, when I scroll everything messes up.
WPFFlexGridScollIssue.zip
Posted 18 June 2025, 9:13 am EST
Hi Kartik
I have added few columns in the grid which you sent and tested, when you scroll columns content messed up.
Posted 20 June 2025, 5:35 am EST
Hi David,
We reviewed the sample project you shared (WPFFlexGridScrollIssue.zip) and observed that scrolling does cause some issues. However, we’re not entirely sure what your exact requirement is, which makes it difficult to verify and correct the logic inside the custom CellFactory.
The original requirement i.e. displaying an image along with text has already been demonstrated in the sample we previously shared (ImageConditional_Updated.zip), and we recommend following that approach.
If your current requirement is different, could you please provide more details or clarify the expected pointers? This will help us better understand the scenario and offer more accurate assistance.
Additionally, the ImageConditional_Updated.zip sample project you attached in your latest response does not reproduce any issues on our end. When we run the project and perform scrolling, everything appears to work as expected.
Best Regards,
Kartik
Posted 22 June 2025, 5:01 am EST - Updated 22 June 2025, 5:06 am EST
Posted 23 June 2025, 5:26 am EST
Hi David,
Thanks for highlighting the issue.
FlexGrid uses cell recycling to improve performance. This means any changes made to a cell or its content need to be properly cleaned up when the cell is reused. In your case, since you are setting the cell content, it’s better to use BindCellContent and UnbindCellContent in the cell factory instead of using CreateCellContent.
class CustomCellFactory : GridCellFactory
{
public override void BindCellContent(GridCellType cellType, GridCellRange range, FrameworkElement cellContent)
{
if (cellType == GridCellType.Cell && range.Column > 0)
{
//show text for cells
var textBlock = (cellContent as Grid).Children[0] as TextBlock;
var cellValue = Grid[range.Row, range.Column];
textBlock.Text = cellValue.ToString();
}
base.BindCellContent(cellType, range, cellContent);
}
public override void UnbindCellContent(GridCellType cellType, GridCellRange range, FrameworkElement cellContent)
{
if (cellType == GridCellType.Cell && range.Column > 0)
{
//show text for cells
var textBlock = (cellContent as Grid).Children[0] as TextBlock;
var cellValue = Grid[range.Row, range.Column];
textBlock.Text = null;
}
base.UnbindCellContent(cellType, range, cellContent);
}
}
Kindly refer to the attached sample for full implementation. [ImageConditional_Mod.zip]
Thanks & regards,
Aastha