Hello,
The default behavior for mouse over effect on a grid row is like this : https://support.syncfusion.com/kb/article/10257/how-to-apply-the-row-mouse-hover-effect-in-wpf-datagrid-sfdatagrid
Based on the example in this article, my requirement is that when you mouse over a row the highligthed rows must be all the rows with the same "Country".
If mouse is over Germany -> 4 rows in rellow
France -> 2 rows
Can you help me with this requirement ?
Thank you.
Nicolas
Hi Nicolas Wagener,
We are currently your requirement, we need time to analyze your validation and will provide an update on or before September 14, 2023.
Regards,
Chidanand M.
Hi Nicolas Wagener,
Your requirement can be achieved by overriding the StyleSelector class and hooking the MouseMove event of the SfDataGrid. We modified the sample based on your requirement and you can find the sample in the attachment.
Kindly refer the below code snippet:
|
public MainWindow() { InitializeComponent(); sfDataGrid.MouseMove += SfDataGrid_MouseMove; sfDataGrid.MouseLeave += SfDataGrid_MouseLeave; }
private void SfDataGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { sfDataGrid.RowStyleSelector = new CustomRowStyleSelector(); }
OrderInfo previousData; private void SfDataGrid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { var visualContainer = this.sfDataGrid.GetVisualContainer(); var point = e.GetPosition(visualContainer); //Here you can get the row and column index based on the pointer position by using PointToCellRowColumnIndex() method var rowColumnIndex = visualContainer.PointToCellRowColumnIndex(point); var recordIndex = this.sfDataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex); if (recordIndex < 0) return; //When the rowindex is zero , the row will be header row if (!rowColumnIndex.IsEmpty) { if (this.sfDataGrid.View != null) { // Get the current row record while grouping var record = this.sfDataGrid.View.Records[this.sfDataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex)]; ; if (record.GetType() == typeof(RecordEntry)) { var data = (record as RecordEntry).Data as OrderInfo; if (data != null && previousData != data) { previousData = data; foreach (var item in view.Orders) { if (item.RowData != null && (item.RowData as OrderInfo).Country == data.Country) { sfDataGrid.RowStyleSelector = new CustomRowStyleSelector(item); break; } } } } } } } }
public class CustomRowStyleSelector : StyleSelector { OrderInfo orderInfo; public CustomRowStyleSelector() { } public CustomRowStyleSelector(DataRowBase dataRow) { orderInfo = dataRow.RowData as OrderInfo; } public override Style SelectStyle(object item, DependencyObject container) { var row = (item as DataRowBase).RowData; var data = row as OrderInfo;
if (orderInfo != null && data.Country == orderInfo.Country) return App.Current.Resources["rowStyle1"] as Style; return null; } } |
We hope this helps. Please let us know, if need any further assistance.
Regards,
Chidanand M
Thank you, it's working almost perfectly.
I deleted my previous response because I found another way to do what I want.
I still need your help about this last concern : When I added an alternate row color to the sample, it's not working everytime.
In the following screenshot, you can see that the alternate color is choosen as the primary color :
How can I override the alternate row color ?
Thank you
Hi Nicolas Wagener,
We are currently analyzing your issue. We need time to validate it, so we will provide an update on or before September 21, 2023.
Regards,
Santhosh.G
Hi Nicolas Wagener,
This issue arises due to the use of the AlternatingRowStyle in the DataGrid. We are currently investigating the possibility of overriding the alternate row color. We require more time for validation, and we will provide further details on September 25, 2023.
Regards,
DhivyaBharathi Dakshinamurthy
Hi Nicolas Wagener,
We have analyzed the reported scenario and found that the AlternatingRowStyle takes precedence over the RowStyleSelector. This is the expected behavior. If you want to use the hovering feature, it's better to avoid using the AlternatingRowStyle property.
We hope this helps. Please let us know, if need any further assistance.
Regards,
Chidanand M.