I have a dotnet framework windows gui app using InfragisticsWPF4.v20.2 upgraded from V14.1, where the following code was working for V14.1, but not working any more even in compiling:
excelWorkSheetRow.Cells[i + level].CellFormat.FillPatternForegroundColor = System.Drawing.Color.LightGray;
Cannot implicitly convert type 'System.Drawing.Color' to 'System.Windows.Media.Color'.
same to CellFormat.BottomBorderColor, CellFormat.LeftBorderColor, and CellFormat.FillPatternForegroundColor
excelWorkSheetRow.Cells[i + level].CellFormat.FillPattern = FillPatternStyle.Solid;
CellFormat.FillPattern is obsolete, it suggests to use Fill - how to?
Please help with some samples. Thanks!
Hello,
Thank you for posting on our forums.
Please note that as per the information in our documentation:
In previous versions, the cell fill was defined by three properties on the IWorksheetCellFormat interface: FillPattern, FillPatternBackgroundColor, and FillPatternForegroundColor. They are all replaced by a single Fill property, which is a reference to a CellFill instance.
IWorksheetCellFormat
FillPattern
FillPatternBackgroundColor
FillPatternForegroundColor
CellFill
https://www.infragistics.com/help/wpf/excelengine-excel-2007-color-model#_Ref320715825
Please check the above link for further information how to set the fill of a cell.
If you have further questions or concerns, please let me know
Sincerely,
Tihomir TonevAssociate Software DeveloperInfragistics
Hi Tihomir Tonev,
Thanks for your quick reply. Can you please share me with some sample how to set Fill property to replace FillPatternForegroundColor, LeftBorderColor, FillPatternForegroundColor, and FillPattern in C#? Thanks!
Hello Weimin,
The CellFormat.Fill basically combines the three properties that you have mentioned above. It could be used as follows with the CreatePatterFill method, which takes 3 arguments – BackGroundColor, PatternColor and FillPaternStyle:
worksheet1.Rows[0].Cells[0].CellFormat.Fill = CellFill.CreatePatternFill(Color.FromRgb(152, 251, 152), Color.FromRgb(0, 0, 0), FillPatternStyle.Solid);
I have also created a small sample application that demonstrates how the Fill property could be applied as well as applying border to the cells.
Please test the sample on your side let me know if you have any questions.
Regards, Ivan Kitanov
ExcellEngineCellFill.zip
Hi Ivan,
Thanks for your sample code. Just wonder now CreatePatternFille() accepts System.Windows.Media.Color as for the foreground/background colors, where you provided Color.FromRgb(152,251,152), how to use System.Drawing.Color, such as, System.Drawing.Color.LightGray, etc? Do they have any function/method to convert from System.Drawing.Color to System.Windows.Media.Color? It is not convenient to use FromRgb() with 3 individual color elements. Please advise. Thanks!
In order to convert from System.Drawing.Color to System.Windows.Media.Color you can use the FromArgb method of the System.Windows.Media.Color and pass the System.Drawing.Color, form it you can obtain the a,r,g and b similar to the code below:
System.Drawing.Color color;
System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
I also recommend you reviewing the following stackoverflow post, that explains in in more details and provides an example of implementing this approach for frequent uses.
Thanks a lot for the quick solution. That's exactly what I wanted. Thanks again, and have great day!
Weimin
Hello Wimin,
I’m glad that you found my suggestion helpful and managed to resolve you issue.
Thank you for choosing Infragistics!