We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to get the underlying record and column based on the mouse position in the SfDataGrid?

In the SfDataGrid, you can get the underlying records, groups, table summaries, group summary, nested record collection and columns based on the mouse position. You can achieve this by using the PointToCellRowColumnIndex () helper method of VisualContainer.

You can use any mouse events to get the record information. In the below example MouseMove event is used.

C#

 

Data Row

The following code example helps you get the record and column under mouse position.

C#

 

For default Data Rows, you can get its underlying data row and column by resolving row and column index into the ResolveToRecordIndex () and ResolveToGridVisibleColumnIndex () helper methods that return the corresponding record index and visible column index.

With the help of record index, you can retrieve record from the Records or TopLevelGroup.DisplayElements when grid is grouped from SfDataGrid.View. By using the visible column index, you can retrieve corresponding Grid Column from SfDataGrid.Columns.

Likewise, you can get the AddNewRow, TableSummaryRow and DetailsViewDataRow.

 

Header Row

The following code example helps you identify whether the mouse point is at Header Row or not.

C#

 

In the above code example, you can get the corresponding rowColumnIndex by passing mouse pointer position (point) to VisualContainer’s PointToCellRowColumnIndex() helper method.

 

Row Header

The following code example helps identify whether the mouse point is hovered at the RowHeader or not.

C#

 

 

Stacked Header Row

When the StackedHeaderRow feature is enabled, consider the StackedHeaderRows count as header row. The following code example helps you identify the stacked header rows in the SfDataGrid.

C#

 

AddNewRow

You can identify whether the mouse point is at AddNewRow or not by passing the corresponding row index to the IsAddNewIndex (int RowIndex) helper method as shown in the following code example.

C#

The above code example is applicable for both Grouping and non-Grouping case.

TableSummaryRow

When the mouse point is hovered at TableSummaryRow, resolve the TableSummaryRowIndex by resolving the rowColumnIndex.RowIndex to ResolveToTableSummaryIndex () helper method. By using the TableSummaryRowIndex, you can retrieve the TableSummaryRow from TableSummaryRows collection from a View of the SfDataGrid as shown in the following code example.

C#

The above code example is applicable for both Grouping and non-Grouping case.

DetailsViewDataRow

When the mouse point is hovered at DetailsViewDataRow, you can also get the corresponding nested records. For this, you need to get the parent row index and it is resolved by passing row index to GetRecordAt() helper method that returns the corresponding parent record entry from view. With the help of that parent record entry you can get the parent row index. By using parent row index, you can get corresponding nested record collection as shown in the following code example.

C#

The above code example is applicable when the columns are not grouped in the SfDataGrid.

CaptionSummaryRow and GroupSummaryRow

In grouping case, when the mouse point is hovered at Group or Caption Summaries, you need to resolve the above record index in the DisplayElements of TopLevelGroup from a View of the SfDataGrid.

The following code example illustrates you to retrieve the corresponding Group, Summary record entry under mouse position as shown in the following code example.

C#

 

 

DetailsViewDataRow with Grouping

The following code example helps you identify whether the mouse point is at DetailsViewDataRow or not when the columns are grouped.

C#

 

Sample Links:

WPF

WinRT

UWP

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
6136 01/25/2016 01/25/2016 UWP SfDataGrid 4.5
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.