Having trouble subscribing GridView events

1 Answer 46 Views
GridView
Shen
Top achievements
Rank 1
Shen asked on 05 Jan 2023, 06:59 AM | edited on 05 Jan 2023, 07:09 AM

Hi, 

I can't find events such as cellClick cellDoubleClick in GridView for wpf, is there anyway subcribing them WinForm style? thanks

 

PS: I think its better if I discribe more details

1.I'm work on  a file managing system, these is a GridView displaying all the files

2.different context menu should appear depending on where right click happens,  so I have to know if the user right click on a row or on a empty space. But I can't find events like cellClick, there is a event named MouseDown in RadGridView but I don't know what's under the cursor.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 05 Jan 2023, 07:42 AM

Hello Shen,

RadGridView for WPF doesn't have dedicated cell click events. Instead, you can use the mouse click events and get the clicked row from the event arguments.

private void RadGridView_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
	var clickedElement = (FrameworkElement)e.OriginalSource;
	GridViewRow row = ParentOfTypeExtensions.ParentOfType<GridViewRow>(clickedElement);
	// if you need the cell element, you can search for GridViewCell
	if (row != null)
	{
		object dataItem = row.Item;
		// open the context menu                
	}
	else
	{
		// click outside of the rows area
		// open the context menu
	}
}

Can you try this and let me know if it helps?

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Shen
Top achievements
Rank 1
commented on 05 Jan 2023, 09:19 AM

It worked, thanks a lot~~
Tags
GridView
Asked by
Shen
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or