This is a migrated thread and some comments may be shown as answers.

mouse click event in grid view?

7 Answers 2068 Views
GridView
This is a migrated thread and some comments may be shown as answers.
trichy
Top achievements
Rank 1
trichy asked on 14 Feb 2011, 07:22 AM
Hello telerik team,
                           is there any mouse click event in rad gridview?
In my last wpf project i want to click on radgridview that time the selected row details display on respective controls?

how to get clicked row data in gridview?

can u suggest some sample code here?

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Feb 2011, 09:49 AM
Hello trichy,

RadGridView does provide a bunch of Mouse-click events (MouseDoubleClick, MouseLeftButtonDown, PreviewMouseRightButtonUp, etc.). However, I am not quite sure what are your exact requirements and consequently, I am not able to provide you with an appropriate solution. Do you want to visualize the RowDetails once the row is selected (that can be achieved by setting the RowDetailsVisibilityMode property of the grid to VisibleWhenSelected) ? Or you want to get the item on selecting it (you may use the SelectionChanged event) ?  

 

All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
vikas gupta
Top achievements
Rank 1
answered on 13 Oct 2011, 03:32 PM
i want row double click event.
if i use mouse double click event.it fire when user click on the header of the gridview.
0
Maya
Telerik team
answered on 13 Oct 2011, 03:39 PM
Hello Vikas Gupta,

Generally, when you double click on a row, RowActivated event will be fired. However, it will be fired for the GridViewHeaderRow as well. What you could do is to verify the type of the row and execute your logic only for the type you want. For example:

private void clubsGrid_RowActivated(object sender, RowEventArgs e)
        {
            if(e.Row is GridViewHeaderRow)
            {
                MessageBox.Show("You clicked on a header row");
            }
            else if(e.Row is GridViewRow)
            {
                MessageBox.Show("You clicked on a row");
            }
        }
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
XXXX
Top achievements
Rank 1
answered on 03 May 2012, 12:24 PM

I find this example to be inaccurate since that event isn't fired when the user double clicks the header row.

I would like to see an example for handling double click on a row that works and show how to access the cell clicked on.

0
Maya
Telerik team
answered on 04 May 2012, 09:10 AM
Hi Bjössi,

If you want to get the cell you double-clicked on, you can work direly with MouseDoubleClick event. For example:

private void clubsGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var clickedElement = e.OriginalSource as FrameworkElement;
            if(clickedElement != null)
            {
                if(clickedElement.ParentOfType<GridViewCell>() != null)
                {
                    MessageBox.Show("You clicked on a cell");
                }
                if (clickedElement.ParentOfType<GridViewHeaderCell>() != null)
                {
                    MessageBox.Show("You clicked on a header cell");
                }
            }
        }

Since double click on a cell places it in edit-mode, you will get the cell either if the grid is read-only or it is already in edit-mode.
Does this approach correspond to your requirements ? 
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
XXXX
Top achievements
Rank 1
answered on 04 May 2012, 10:26 AM

I had seen this code before and it doesn't work for me (and some other according to the forums).

I get a compile error saying that ParentOfType is not a part of FrameworkElement. This could be caused by incorrect "using" but I used JustCode to add the missing "using".

Beside that this code does not demonstrate how to access the value of the clicked cell or specific cell in the clicked row.

My workaround for this task was to use the GridRowActivated event and then get the underlying data with  (e.Row.DataContext as DataRow).ItemArray[0] .

This works for me since I will always be acting up on the first column but not clicked cell.

I have been using Telerik RadControls for Windows and ASP.NET (and .. ...)  where documentation is very verbose and detailed. That gives the impression that the documentation for the WPF controls is minimal. The maturity of the other platforms explains the difference, you at Telerik have spoiled us with good support so we expect nothing short of perfect, keep up the good work.

0
Maya
Telerik team
answered on 04 May 2012, 11:41 AM
Hi Bjössi,

You need to add reference to Telerik.Windows.Controls assembly in the class you use ParentOfType<T>() and ChildrenOfType<T> extension methods. As for getting the value of the cell, you can just cast the element you found through ParentOfType<GridViewCell>() method and get its Value property.
Considering our documentation, we really make a lot of efforts for improving it and including all the information that might be helpful for our customers. And I am really happy to see that our support delivers what you expect and hopefully even more.  
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
trichy
Top achievements
Rank 1
Answers by
Maya
Telerik team
vikas gupta
Top achievements
Rank 1
XXXX
Top achievements
Rank 1
Share this question
or