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 BasicPrivate 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
I have just one HyperLinkEdit column, I have just one event and I'm testing to see if I can close the form on the event
I have this.Close() only in the MouseDown event. Why the app is crashing ?
I need to close the form on the MouseDown event of the GridView
DevExpress Version 12.1.8
Windows 8 Pro
Visual Studio 2012
.NET Framework 4.5
at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcHitInfo(Point pt)
at DevExpress.XtraGrid.Views.Grid.Handler.GridHandler.OnMouseDown(MouseEventArgs ev)
at DevExpress.Utils.Controls.BaseHandler.ProcessEvent(EventType etype, Object args)
at DevExpress.XtraGrid.GridControl.OnMouseDown(MouseEventArgs ev)
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message& m)
at DevExpress.XtraGrid.GridControl.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at AccesManager.Program.Main() in c:\AccessManager\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
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.
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?
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.