RepositoryItemHyperLinkEdit.OpenLink Event
Occurs before hyperlink execution.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
Event Data
The OpenLink event's data class is OpenLinkEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
EditValue | Gets or sets the object representing the command to execute. |
Handled | Gets or sets whether default execution of the hyperlink command is required. |
Remarks
The OpenLink event is fired before hyperlink execution. The event allows you to modify the command to execute, perform your action(s) and cancel default processing (if necessary).
The event occurs when the end-user activates hyperlink functionality or when the HyperLinkEdit.ShowBrowser method is called. It is possible to execute the hyperlink command by clicking or double-clicking the edit box (according to the RepositoryItemHyperLinkEdit.SingleClick property) and by pressing the RepositoryItemHyperLinkEdit.StartKey shortcut.
The sender event parameter specifies the hyperlink editor which fires the event. The second event parameter contains data related to the event.
OpenLinkEventArgs.EditValue specifies the value of the editor’s BaseEdit.EditValue property. This represents the command to execute. You are able to modify the command depending on your needs. After running your OpenLink event handler, the editor will execute this command unless the OpenLinkEventArgs.Handled property has been set to true, to prevent the default command execution.
The editor’s HyperLinkEdit.OpenLink event is equivalent to the current event.
Example
Suppose that a hyperlink editor is used to display e-mails. When you activate the hyperlink, the default mail client should be opened for the specified address. The problem is that a hyperlink editor will run the mail client only if the command contains a “mailto:” prefix. So a command such as “noreply@devexpress.com” is not recognized by the editor by default.
Assuming that the hyperlink editor represents e-mails, we handle the HyperLinkEdit.OpenLink event and check whether the command contains the “mailto:” prefix. If not, we add it to the command. After the event handler is processed, the command will be executed by the editor (the OpenLinkEventArgs.Handled property of the event parameter is false by default) and this will open the mail client.
using DevExpress.XtraEditors.Controls;
this.hyperLinkEdit2.EditValue = "noreply@devexpress.com";
//...
private void hyperLinkEdit2_OpenLink(object sender, OpenLinkEventArgs e) {
const string mailPrefix = "mailto:";
if(!e.EditValue.ToString().ToLower().StartsWith(mailPrefix)) {
e.EditValue = mailPrefix + e.EditValue.ToString();
}
}