[VB.net] Highlight Single Cell in SfDatagrid

Hi,
my goal is to highlight a single cell in SfDatagrid as it happens for Row Header like this picture:
https://ibb.co/S6fh3Gg

I followed example at this link:

https://www.syncfusion.com/kb/11276/how-to-apply-the-row-mouse-hover-effect-in-datagridsfdatagrid

So I created this code in order to highlight the row in order to follow example in link above:
Private Sub SfDataGrid1_mouseover(ByVal sender As Object, ByVal e As MouseEventArgs) Handles SfDataGrid1.MouseMove
        Dim cc = 1
        Dim rowColumnIndex = Me.SfDataGrid1.TableControl.PointToCellRowColumnIndex(Me.SfDataGrid1.TableControl.PointToClient(Cursor.Position))
 End Sub

But I cannot enter in this sub

Can you help me please?
Thank in advanced 
gio

6 Replies 1 reply marked as answer

GI Giovanni May 11, 2021 08:32 AM UTC

Hi,
enclosed file as example.
I will never enter in sub MouseHover or MouseMove

br
gio

Attachment: SfDatagrid_af921100.rar


MA Mohanram Anbukkarasu Syncfusion Team May 11, 2021 09:07 AM UTC

Hi Giovanni, 

Thanks for contacting Syncfusion support.  

You have to make use of the SfDataGrid.TableControl.MouseMove event as shown in the following code example.  

Code example :  

AddHandler Me.sfDataGrid1.TableControl.MouseMove, AddressOf TableControl_MouseMove 
AddHandler Me.sfDataGrid1.TableControl.MouseMove, AddressOf TableControl_MouseMove 
AddHandler Me.sfDataGrid1.QueryCellStyle, AddressOf SfDataGrid1_QueryCellStyle 
 
Private Sub TableControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) 
       Dim rowColumnIndex = Me.sfDataGrid1.TableControl.PointToCellRowColumnIndex(Me.sfDataGrid1.TableControl.PointToClient(Cursor.Position)) 
 
    If hoveredRowColumnIndex <> rowColumnIndex Then 
        sfDataGrid1.TableControl.Invalidate(sfDataGrid1.TableControl.GetCellRectangle(hoveredRowColumnIndex.RowIndex, hoveredRowColumnIndex.ColumnIndex, True)) 
        hoveredRowColumnIndex = rowColumnIndex 
        sfDataGrid1.TableControl.Invalidate(sfDataGrid1.TableControl.GetCellRectangle(hoveredRowColumnIndex.RowIndex, hoveredRowColumnIndex.ColumnIndex, True)) 
    End If 
End Sub 
 
Private Sub SfDataGrid1_QueryCellStyle(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs) 
       If e.RowIndex = hoveredRowColumnIndex.RowIndex AndAlso e.ColumnIndex = hoveredRowColumnIndex.ColumnIndex Then 
              e.Style.BackColor = Color.Yellow 
       End If 
End Sub 
 
Private Sub TableControl_MouseLeave(ByVal sender As Object, ByVal e As EventArgs) 
       hoveredRowColumnIndex = New RowColumnIndex(-1, -1) 
End Sub 


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

GI Giovanni May 11, 2021 10:49 AM UTC

Hi Mohanram,
thanks for your reply.
But, why cannot I handle tableControl directly in sub like below?

Private Sub TableControl_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles sfDataGrid1.TableControl.MouseMove
...
End Sub

Thank in advanced
gio


MA Mohanram Anbukkarasu Syncfusion Team May 12, 2021 01:18 PM UTC

Hi Giovanni, 

Thanks for the update.  

You can handle only the event of the Form as you have mentioned. You have to make use of the AddHandler to handle the events of the SfDataGrid.TableControl as we mentioned in our previous update. Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



GI Giovanni May 13, 2021 09:19 AM UTC

Hi Mohanram,
thanks.
I understood what you mean.
Ticket can be closed.

BR,
gio


MA Mohanram Anbukkarasu Syncfusion Team May 14, 2021 05:05 AM UTC

Hi Giovanni, 

Thanks for the update.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon