is it possible to drop a hyperlink object - as a custom cell, no doubt - into a virtual grid
I downloaded the example from another post in this forum but it was for a checkbox
I found a HyperlinkElement but it is calling for the specific row and column before instantiating
any assistance is greatly appreciated
3 Answers, 1 is accepted
Hello, Marianne,
Your question has already been answered in the support ticket that you have opened on the same topic. Please, see our answer there for more information.
However, I am posting the solution suggested by my colleague, Lance, here as well in order the community to benefit from it.
Although the tutorial is for a checkbox, you can use whatever custom element you want. If you don't already have a preferred way of rendering hyperlinks in WinForms, you could try a RadLabelElement and use the RadLabel HTML-like formatting feature.
public class VirtualGridHyperlinkCellElement : VirtualGridCellElement
{
private RadLabelElement aLabel;
protected override void CreateChildElements()
{
base.CreateChildElements();
aLabel = new RadLabelElement();
this.Children.Add(aLabel);
}
protected override void UpdateInfo(VirtualGridCellValueNeededEventArgs args)
{
base.UpdateInfo(args);
if (args.Value is string)
{
aLabel.Text = args.Value.ToString();
}
this.Text = string.Empty;
}
public override bool IsCompatible(int data, object context)
{
VirtualGridRowElement rowElement = context as VirtualGridRowElement;
return data == 6 && rowElement.RowIndex >= 0;
}
public override void Attach(int data, object context)
{
base.Attach(data, context);
// Subscribe to the RadLabelElement's click event when the cell is attached.
aLabel.Click += ALabel_Click;
}
public override void Detach()
{
// Unsubscribing when the cell is detached (prevents memory leak).
aLabel.Click -= ALabel_Click;
base.Detach();
}
private void ALabel_Click(object sender, EventArgs e)
{
var theFilePath = "";
Process.Start(theFilePath);
}
}
The above code snippet relies on the fact that the cell stores the URL. Thus, when it is clicked, the process is started.
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and extend it in a way which suits your requirements best.
We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
Thank you for your understanding.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Yes, Dess, that is my code - but I needed to make some corrections
add a private string variable called filePath to the class
set this variable in the UpdateInfo method
use the class variable in the Process.Start in the label click event handler (remove the string variable in the method - it isn't needed)
finally, surround the args value with an <a> within a <span> within an <html> putting the args value in the href property of the <a> tag
Hello, Marianne,
Thank you for the provided detailed improvements of the previously suggested code snippet.
I believe that it would be helpful for the community.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.