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

Chnage RadGridViewColumn to Hyperlink not working

6 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 21 Aug 2018, 11:36 AM

Hi,

 

I'm creating a radgridview from an existing datatable. I need one column to have all its cells as hyperlinks to a directory.

I tried:

GridViewHyperlinkColumn gridViewHyperlinkColumn = new GridViewHyperlinkColumn()
{
Header = "test",
TargetName = "c://" + rowValue
};
 
gridViewHyperlinkColumn.PreviewMouseDown += OpenTarget;
 
datarow[column] = gridViewHyperlinkColumn;

 

 

But the cell shows the following result: Telerik.Windows.Controls.GridViewHyperlinkColumn instead of showing the row value underlined.

 

Can anyone help me?

 

Regards


6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 Aug 2018, 10:39 AM
Hi Ricardo,

In order to display the needed property value in the cell of the column the DataMemberBinding of GridViewHyperlinkColumn needs to be set. Please, take a look at the Hyperlink Column topic and Column Types WPF Demo for more information on the matter.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ricardo
Top achievements
Rank 1
answered on 23 Aug 2018, 11:11 AM

Hi Stefan,

 

I followed the example and tried the following:

string url = "c://";
 
Binding binding = new Binding(url)
{
     Mode = BindingMode.OneWay,
     UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged                           
};
 
GridViewHyperlinkColumn gridViewHyperlinkColumn = new GridViewHyperlinkColumn()
{
      Header = rowValue,
      TargetName = url,
      DataMemberBinding = binding
 };

 

But the row display stayed the same: Telerik.Windows.Controls.GridViewHyperlinkColumn

0
Accepted
Stefan
Telerik team
answered on 28 Aug 2018, 10:08 AM
Hello Ricardo,

Thanks for the update.

As demonstrated in the referred article, the DataMemberBinding of the column needs to be bound to a property of the bound object. This property, on the other hand, can return the needed url. I have prepared a sample application as a demonstration for your convenience.

I hope this helps.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ricardo
Top achievements
Rank 1
answered on 28 Aug 2018, 09:24 PM

Hi Stefan,

I followed the example and tried:

TeamUrl = "C://";
 
                        Binding binding = new Binding(TeamUrl)
                        {
                            Mode = BindingMode.OneWay,
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                        };
 
                        GridViewHyperlinkColumn gridViewHyperlinkColumn = new GridViewHyperlinkColumn()
                        {
                            Header = "Header",
                            TargetName = TeamUrl,
                            TextDecorations = TextDecorations.Underline,
                            DataMemberBinding = binding
                        };
 
                        gridViewHyperlinkColumn.PreviewMouseDown += OpenTarget;
 
 TableGridView.Columns.Add(gridViewHyperlinkColumn);

 

TableGridView.Items.Add(TeamUrl);

But i get an error:

System.Windows.Data Error: 40 : BindingExpression path error: 'C:' property not found on 'object' ''String' (HashCode=15947561)'. BindingExpression:Path=C://; DataItem='String' (HashCode=15947561); target element is 'HyperlinkButton' (Name=''); target property is 'Content' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'C:' property not found on 'object' ''String' (HashCode=15947561)'. BindingExpression:Path=C://; DataItem='String' (HashCode=15947561); target element is 'HyperlinkButton' (Name=''); target property is 'NavigateUri' (type 'Uri')

 

I also tried :

TeamUrl = "C://";
                        Binding binding = new Binding(TeamUrl)
                        {
                            Mode = BindingMode.OneWay,
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                        };
                        GridViewHyperlinkColumn gridViewHyperlinkColumn = new GridViewHyperlinkColumn()
                        {
                            Header = "Header",
                            TargetName = TeamUrl,
                            TextDecorations = TextDecorations.Underline,
                            DataMemberBinding = binding
                        };
                        gridViewHyperlinkColumn.PreviewMouseDown += OpenTarget;
TableGridView.Columns.Add(gridViewHyperlinkColumn);

 

TableGridView.Items.Add(new Uri(TeamUrl));

But a bunch of columns appeared and when none of them allows me to click and open the folder.

0
Accepted
Stefan
Telerik team
answered on 30 Aug 2018, 03:42 PM
Hi Ricardo,

I can confirm that the column needs to be bound to a property of the bound data item. The Binding cannot be defined to point directly to the file path. Instead, the bound item can have a string property and the filed of this property can return the file path. Please, refer to the example provided with my previous reply as it demonstrates the approach.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ricardo
Top achievements
Rank 1
answered on 30 Aug 2018, 04:06 PM
thanks for the help Stefan, i found another way to "mask" the column as a Hyperlink column without needing to define the column or bindings. I just created a style, that simulates a hyperlink, and when the user clicks on it, it opens the directory.
Tags
GridView
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Ricardo
Top achievements
Rank 1
Share this question
or