KB Article A2905
Visible to All Users

How to make a read-only Hyper link column launch a web browser when a link is clicked

Description:
I have a HyperLink column, which I do not want to be edited by end users. So I set its Options.Editing to False. But in this case, the Properties.OnStartClick event never fires. Is it possible to start a web browser when a user clicks a hyper link, but prevent them from editing the hyper link column?

Answer:
If the RepositoryItemHyperLinkEdit.TextEditStyle property is set to DisableTextEditor, editing is disabled. At the same time, it is possible to activate a hyperlink with double or a single mouse click.

older versions:

It is possible to achieve this by using the GridView's MouseDown event and analyzing the column under the mouse cursor. If it is a Hyper link column, you should obtain the clicked cell's value and manually start the webbrower. Here is some sample code illustrating this approach:

C#
private void gridView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { GridHitInfo hi = (sender as GridView).CalcHitInfo(new Point(e.X, e.Y)); if (hi.InRowCell && hi.Column.ColumnEdit is DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit) { Process process = new Process(); object v = (sender as GridView).GetRowCellValue(hi.RowHandle, hi.Column); process.StartInfo.FileName = (v == null ? string.Empty : v.ToString()); process.StartInfo.Verb = "open"; process.StartInfo.WindowStyle = ProcessWindowStyle.Normal; try { process.Start(); } catch {} } }
Visual Basic
Private Sub GridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GridView1.MouseDown Dim hi As GridHitInfo = CType(sender, GridView).CalcHitInfo(New Point(e.X, e.Y)) If (hi.InRowCell AndAlso TypeOf hi.Column.ColumnEdit Is DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit) Then Dim process As Process = New Process Dim v As Object = CType(sender, GridView).GetRowCellValue(hi.RowHandle, hi.Column) process.StartInfo.FileName = IIf(IsNothing(v), String.Empty, v.ToString()) process.StartInfo.Verb = "open" process.StartInfo.WindowStyle = ProcessWindowStyle.Normal Try process.Start() Catch End Try End If End Sub

In the attachment you will find a sample project which demonstrates this approach.
See also:
998
2904

Show previous comments (1)
DevExpress Support Team 12 years ago

    Hi,
    To avoid any misunderstanding in the discussion of this behavior, I have cloned your inquiry in a separate ticket.
    Please refer to the following thread where we will continue our discussion: The NullReference exception is raised in the GridView.MouseDown event handler
    We appreciate your cooperation.

    AK AK
    Andrey Kosteley (Xafari Team) 8 years ago

      Do you know if the article is relevant at the moment?
      And is this the only way to open a link if the view is not in edit mode?

      Andrew Ser (DevExpress Support) 8 years ago

        Hello Andrey,
        As far as I can see, this article is relevant. In any case, let's discuss this topic in detail in a separate ticket I've created on your behalf - Grid - How to activate a read-only HyperLink. Thank you for your cooperation in advance.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.