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

Get a column value on double click?

6 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kenny
Top achievements
Rank 1
Kenny asked on 02 Jun 2009, 06:19 PM
Hello all,
I'm using RadGrid to displays items from a table. One of the column in a row stores the path to a file, how do I get the value of that particular column on double click (on the row) so that I can displays the file's path and display the file (I'll be using DocumentViewer to display the file.)

Thanks,
Kenny.

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Jun 2009, 08:40 AM
Hi Kenny,

You can find small example attached.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenny
Top achievements
Rank 1
answered on 03 Jun 2009, 05:44 PM
Hi Vlad,
Is there a way to modify your code so that it will return the value of the column that I want (the file's path) regardless of where I click on that row? Here is what my grid looks like:

<telerik:RadGridView Name="radGridViewMusicSheets" telerik:StyleManager.Theme="Office_Black" 
                                     ShowGroupPanel="False" IsFilteringAllowed="True" 
                                     Foreground="Black" Margin="0,35,0,10" AutoGenerateColumns="False" 
                                     RowIndicatorVisibility="Collapsed" ColumnsWidthMode="Fill" IsReadOnly="True"
 
                        <telerik:RadGridView.Columns> 
                            <telerik:GridViewDataColumn UniqueName="Title" HeaderText="Title" IsFilterable="False" /> 
                            <telerik:GridViewDataColumn UniqueName="Artist" HeaderText="Artist" Width="Auto" /> 
                            <telerik:GridViewDataColumn UniqueName="Key" HeaderText="Key" Width="Auto"/> 
 
                            <!-- Hidden Columns For Search Purposes--> 
                            <telerik:GridViewDataColumn UniqueName="Title2" HeaderText="Title2" IsVisible="False" /> 
                            <telerik:GridViewDataColumn UniqueName="Artist2" HeaderText="Artist2" IsVisible="False" /> 
                            <telerik:GridViewDataColumn UniqueName="ID" HeaderText="ID" IsVisible="False" /> 
                            <telerik:GridViewDataColumn UniqueName="FilePath" HeaderText="FilePath" IsVisible="False" /> 
                        </telerik:RadGridView.Columns> 
                    </telerik:RadGridView> 


And I only want the value of the last column (FilePath).

Thanks again for your help,
Kenny.
0
Accepted
Vlad
Telerik team
answered on 04 Jun 2009, 05:47 AM
Hello Kenny,

Here is an example:
        void RadGridView1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            UIElement clicked = e.OriginalSource as UIElement;
            if (clicked != null)
            {
                GridViewRow row = clicked.ParentOfType<GridViewRow>();
                if (row != null)
                {
                    GridViewCell cell = row.ChildrenOfType<GridViewCell>().Where(c=>c.Column.UniqueName == "FilePath").FirstOrDefault();
                    if (cell != null)
                    {
                        MessageBox.Show(cell.Content.ToString());
                    }
                }
            }
        }

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenny
Top achievements
Rank 1
answered on 04 Jun 2009, 02:45 PM
Hi Vlad,
The code won't return me the value if I set the column's visible to false? But I don't want to display that column, I just want to get the value, is there a way to do that?

Thanks again for your helps,
Kenny.
0
Vlad
Telerik team
answered on 04 Jun 2009, 02:53 PM
Hello Kenny,

You can get directly desired property from row.DataContext - you will need to cast it to your type.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kenny
Top achievements
Rank 1
answered on 04 Jun 2009, 04:35 PM
Thanks a lot Vlad, I'll poke around :)
Tags
GridView
Asked by
Kenny
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kenny
Top achievements
Rank 1
Share this question
or