<Style x:Key="cellStyle" TargetType="syncfusion:GridCell">
<Setter Property="Background" Value="LightBlue" />
</Style>
<syncfusion:SfDataGrid.RecordContextMenu>
<ContextMenu Style="{x:Null}">
<MenuItem Command="{Binding Source={x:Static Member=local:ContextMenuCommands.Color}}"
CommandParameter="{Binding}"
Header="ChangeColor">
</MenuItem>
</ContextMenu>
</syncfusion:SfDataGrid.RecordContextMenu>
|
private static void OnColorClicked(object obj)
{
if (obj is GridRecordContextMenuInfo)
{
var grid = (obj as GridRecordContextMenuInfo).DataGrid;
var currentcell = grid.SelectionController.CurrentCellManager.CurrentCell;
if (currentcell == null)
return;
var cell = (currentcell.Renderer as GridCellRendererBase).CurrentCellElement;
&nb
VP
Valery Piashchynski
May 1, 2016 08:04 PM UTC
Thx, it helps. But i have another one question. If i change (for example) cell backgroung property due programm is working, how can i save this state of cell? After restarting all cells are at default style. I am try BinaryFormatter/XmlSerializer/SfDataGrid.Serialize but it dont work.
JG
Jai Ganesh S
Syncfusion Team
May 2, 2016 12:40 PM UTC
Hi Valery,
We have analyzed your query. In the sample, you have changed the Grid cell style at run time. And this changes are maintaining the Underlying collection. In this case you have own to serialize the setting in sample level and no need to serialize the DataGrid.
Regards,
Jai Ganesh S
VP
Valery Piashchynski
May 2, 2016 07:29 PM UTC
Thank you for answer. But i am change color of cell not by Style in StyleSelector (like in you sample) i change directly Cell.Background property because i need to mark cell by one of 3 different colors selected in SfDataGridRecordContextMenu.
If you can, explain, in what collection these values are stored? (to serialize it) Or i must create own collection with cells properties? How i change cell color: private static void AddGreenColor(object obj) { GridRecordContextMenuInfo info = obj as GridRecordContextMenuInfo; if (info == null) throw new ArgumentNullException(nameof(info)); SfDataGrid grid = ((GridRecordContextMenuInfo)obj).DataGrid; DataColumnBase currentcell = grid.SelectionController.CurrentCellManager.CurrentCell; FrameworkElement cell = (currentcell.Renderer as GridCellRendererBase)?.CurrentCellElement; cell.SetValue(Control.BackgroundProperty, Brushes.Green); grid.UpdateDataRow(currentcell.RowIndex); } Thank you
JG
Jai Ganesh S
Syncfusion Team
May 3, 2016 12:49 PM UTC
Hi Valery,
In your code snippet, you have directly applied the cell style while the cell is pressed. In this case the values are not stored anywhere and you own create a collection to store the cell values. For the below code snippet, we have stored the column index in ColoredRows collection like that you can create the own collection and store the cell values.
Regards,
Jai Ganesh S
SIGN IN To post a reply.
9/01/2024 12:41:04 AM
Sat, 03 December 2022 16:59:00 UTC
12/03/2022 04:59:00 AM
Wed, 16 Feb 2022 04:59:00 UTC
![]() |