Author Topic: datagridview right click get row/column values  (Read 15641 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
datagridview right click get row/column values
« on: October 26, 2013, 12:53:24 PM »
Hi All,

I'm looking for some links on how to right click a data grid view and retrieve values, in my case I'm looking for values in column 7 & 8 from whatever row I select from, see attached jpg.
I was able to test right click with below sample of a selected cell but I can't find anything that shows how to grab columns from a selected row.

the plan is to try and use x,y values to zoom to location with some kind of scale factor or whatever they call it to zoom above or out from location. if I can test
with the MsgBox until I can find the zoom sample

 
Code: [Select]
Private Sub DataGridView2_CellMouseDown(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseDown
        If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then
           ("Value= " & sender.CurrentCell.EditedFormattedValue())
       End If
    End Sub

fixo

  • Guest
Re: datagridview right click get row/column values
« Reply #1 on: October 26, 2013, 03:02:29 PM »
Try this event, just change column numbers to your suit
 
Code: [Select]
  Private Sub DataGridView2_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView2.MouseDown

        If e.Button = Windows.Forms.MouseButtons.Right Then
            Dim hi As DataGridView.HitTestInfo = Me.DataGridView2.HitTest(e.Location.X, e.Location.Y)
            MessageBox.Show(Me.DataGridView2(5, hi.RowIndex).Value.ToString() + vbLf + Me.DataGridView2(6, hi.RowIndex).Value.ToString())
        End If
    End Sub

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #2 on: October 27, 2013, 10:42:31 AM »

fixo,

Thanks for the sample, I looked for several days over the net and could not find any samples that showed how to retrieve values from columns in a data grid.
I'll see if I can get this to work with your help.

Thank you
john

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #3 on: October 27, 2013, 10:45:02 AM »

fixo,

that worked like a charm!  thanks so much......now to see if I can get zoom to location

thanks
john
 
Code: [Select]
If e.Button = Forms.MouseButtons.Right Then
            Dim hi As DataGridView.HitTestInfo = Me.DataGridView2.HitTest(e.Location.X, e.Location.Y)
            MsgBox(Me.DataGridView2(6, hi.RowIndex).Value.ToString() + vbLf + Me.DataGridView2(7, hi.RowIndex).Value.ToString())
        End If

fixo

  • Guest
Re: datagridview right click get row/column values
« Reply #4 on: October 27, 2013, 03:40:34 PM »
You're quite welcome
Cheers, mate :)

Bert

  • Guest
Re: datagridview right click get row/column values
« Reply #5 on: October 29, 2013, 07:04:57 AM »
now to see if I can get zoom to location

Hey jcoon, did you manage to zoom to your location ? Is this a single point, or is this an overview of several selected points ?

I have a situation where I have a selection (1 or more) in a TreeView that represents BlockReferences in ModelSpace.
With a menu bound to right-mouse button I allow users to chose "Zoom to". This collects the extents (maxbounds) of all selected Blockreferences and picks the lower-left & upper-right point.
Then it does a zoom-window on these outer-points.

If you still want/need this I could dig up and share this code with you ?

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #6 on: November 03, 2013, 11:59:07 AM »
Bert,

I'm working on it this weekend, I'll let you know how it goes. my home lic ran out this week so I have to write at home and test at work until I get IT to issue new lic.

my goal will be to zoom/view multiple items in a gridview, treeview sounds interesting, maybe I can work both. only reason I went with gridview vs treeview was I couldn't find a way to add more than one value to a tree node so user could view all that data about that point on one line, I would of like to try the treeview for this sample.

I'll post as soon as I get something working. others here have always help me, unfortunately I've needed so much help trying to move to vb that I hardly have input that might be able to help anyone! maybe in this case it could change.
john

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #7 on: November 03, 2013, 12:02:14 PM »
anything posted you can offer would be great, I'm sure it could help others as well, as I said if I find something that I can get to work I'll post

Bert

  • Guest
Re: datagridview right click get row/column values
« Reply #8 on: November 04, 2013, 03:39:51 AM »
How my solution works :
As i said i've got BlockReferences from the active ModelSpace listed in a Treeview. (Not a DataGrid, but its comparable)
Correct, you can only add 1 'value' to a TreeViewNode, but I do compose the text-value of each node with several types of info & data. Seperating them with a " / ".
A property the TreeViewNode has is the 'tag' wich Visual Studio describes as 'User-defined data associated with the object'. I basically use this to store the ObjectId of the BlockReference represented on that TreeViewNode. (It is not visible on the TreeView)

The 'Zoom - To' button on my form works like this :

'Click-event
Code - vb.net: [Select]
  1.     Private Sub ZoomNaarToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZoomNaarToolStripMenuItem.Click
  2.         If Not MSBOMTreeView.SelectedNode Is Nothing Then
  3.             'Zoom to the BlockReferences by the active selected TreeNode
  4.             ZoomBlockReferenceFromMSTreeView(MSBOMTreeView.SelectedNode)
  5.         End If
  6.     End Sub
  7.  

'Method that collects zoom-to points
Code - vb.net: [Select]
  1.     Private Sub ZoomBlockReferenceFromMSTreeView(sourceNode As TreeNode)
  2.  
  3.         UnhighlightAllBlockReferencesInModelSpace()
  4.  
  5.         Dim pntsColl As New List(Of Autodesk.AutoCAD.Geometry.Point3d)
  6.  
  7.         'Check if there is an ActiveDocument available
  8.         If Not Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Is Nothing Then
  9.             ' Get the current document and database, and start a transaction
  10.             Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  11.             '' Lock the new document
  12.             Using acLckDoc As DocumentLock = acDoc.LockDocument()
  13.  
  14.                 'Get Database of current Document
  15.                 Dim acCurDb As Database = acDoc.Database
  16.  
  17.                 Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  18.                     ' Open the Block table record for read
  19.                     Dim acBlkTbl As BlockTable
  20.                     acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
  21.  
  22.                     ' Open the Block table record ModelSpace for read
  23.                     Dim acBlkTblRec As BlockTableRecord
  24.                     acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead)
  25.  
  26.                     ''' I did remove code here that checks
  27.                     '''   a) what level the selected TreeNode has in the TreeView
  28.                     '''   b) if the selected TreeNode holds more then 1 ObjectId (multiple Blockreferences on 1 TreeNode)
  29.  
  30.                             Dim ent As Entity = DirectCast(acTrans.GetObject(acCurDb.GetObjectId(False, New Handle(Convert.ToInt64(sourceNode.Tag)), 0), OpenMode.ForRead), Entity)
  31.                             If (TypeOf ent Is BlockReference) Then
  32.                                 'Get the BlockReference , add the GeomtericExtents to a collection, and highlight the BlockReference
  33.                                 Dim bref As BlockReference = DirectCast(acTrans.GetObject(ent.ObjectId, OpenMode.ForWrite), BlockReference)
  34.                                 pntsColl.Add(bref.GeometricExtents.MinPoint)
  35.                                 pntsColl.Add(bref.GeometricExtents.MaxPoint)
  36.                                 bref.Highlight()
  37.                             End If
  38.                         End If
  39.  
  40.                 End Using
  41.             End Using
  42.  
  43.             ' Order the collection in that way that the First Point will be the minimal bound point
  44.             ' and the last point is the maximal bound-point of our collection
  45.  
  46.             Dim MinX As Double = pntsColl.First.X
  47.             Dim MaxX As Double = pntsColl.First.X
  48.             Dim MinY As Double = pntsColl.First.Y
  49.             Dim MaxY As Double = pntsColl.First.Y
  50.  
  51.             For Each Pnt As Autodesk.AutoCAD.Geometry.Point3d In pntsColl
  52.                 If Pnt.X < MinX Then MinX = Pnt.X
  53.                 If Pnt.X > MaxX Then MaxX = Pnt.X
  54.                 If Pnt.Y < MinY Then MinY = Pnt.Y
  55.                 If Pnt.Y > MaxY Then MaxY = Pnt.Y
  56.             Next
  57.  
  58.             Dim MinPnt As New Autodesk.AutoCAD.Geometry.Point3d(MinX, MinY, 0)
  59.             Dim MaxPnt As New Autodesk.AutoCAD.Geometry.Point3d(MaxX, MaxY, 0)
  60.  
  61.             'Zoom using Window between these 2 points
  62.             Dim dist As Double = MinPnt.DistanceTo(MaxPnt)
  63.             Dim MinPoint As New Autodesk.AutoCAD.Geometry.Point3d(Math.Round(MinPnt.X - dist / 10, 0), Math.Round(MinPnt.Y - dist / 10, 0), 0)
  64.             Dim MaxPoint As New Autodesk.AutoCAD.Geometry.Point3d(Math.Round(MaxPnt.X + dist / 10, 0), Math.Round(MaxPnt.Y + dist / 10, 0), 0)
  65.  
  66.  
  67.             Acad.ZoomWindow(MinPoint, MaxPoint)
  68.  
  69.         End If
  70.     End Sub
  71.  

Code - vb.net: [Select]
  1.     Public Shared Sub ZoomWindow(_pMin As Point3d, _pMax As Point3d)
  2.         '' Zoom to a window
  3.         Zoom(_pMin, _pMax, New Point3d(), 1)
  4.     End Sub
  5.  
  6.     Shared Sub Zoom(ByVal pMin As Point3d, ByVal pMax As Point3d, ByVal pCenter As Point3d, ByVal dFactor As Double)
  7.  
  8.         '' Get the current document and database
  9.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  10.         Dim acCurDb As Database = acDoc.Database
  11.  
  12.         Dim nCurVport As Integer = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"))
  13.  
  14.         '' Get the extents of the current space when no points
  15.         '' or only a center point is provided
  16.         '' Check to see if Model space is current
  17.         If acCurDb.TileMode = True Then
  18.             If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then
  19.                 pMin = acCurDb.Extmin
  20.                 pMax = acCurDb.Extmax
  21.             End If
  22.  
  23.         Else
  24.             '' Check to see if Paper space is current
  25.             If nCurVport = 1 Then
  26.                 If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then
  27.                     pMin = acCurDb.Pextmin
  28.                     pMax = acCurDb.Pextmax
  29.                 End If
  30.             Else
  31.                 '' Get the extents of Model space
  32.                 If pMin.Equals(New Point3d()) = True And pMax.Equals(New Point3d()) = True Then
  33.                     pMin = acCurDb.Extmin
  34.                     pMax = acCurDb.Extmax
  35.                 End If
  36.             End If
  37.         End If
  38.  
  39.         '' Start a transaction
  40.         Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  41.  
  42.             '' Get the current view
  43.             Using acView As ViewTableRecord = acDoc.Editor.GetCurrentView()
  44.                 Dim eExtents As Extents3d
  45.  
  46.                 '' Translate WCS coordinates to DCS
  47.                 Dim matWCS2DCS As Matrix3d
  48.                 matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection)
  49.                 matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS
  50.                 matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist, acView.ViewDirection, acView.Target) * matWCS2DCS
  51.  
  52.                 '' If a center point is specified, define the
  53.                 '' min and max point of the extents
  54.                 '' for Center and Scale modes
  55.                 If pCenter.DistanceTo(Point3d.Origin) <> 0 Then
  56.                     pMin = New Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0)
  57.                     pMax = New Point3d((acView.Width / 2) + pCenter.X, (acView.Height / 2) + pCenter.Y, 0)
  58.                 End If
  59.  
  60.                 '' Create an extents object using a line
  61.                 Using acLine As Autodesk.AutoCAD.DatabaseServices.Line = New Line(pMin, pMax)
  62.                     eExtents = New Extents3d(acLine.StartPoint, acLine.EndPoint) 'Extents3d(acLine.Bounds.Value.MinPoint, acLine.Bounds.Value.MaxPoint)
  63.                 End Using
  64.  
  65.                 '' Calculate the ratio between the width and height of the current view
  66.                 Dim dViewRatio As Double
  67.                 dViewRatio = (acView.Width / acView.Height)
  68.  
  69.                 '' Tranform the extents of the view
  70.                 matWCS2DCS = matWCS2DCS.Inverse()
  71.                 eExtents.TransformBy(matWCS2DCS)
  72.  
  73.                 Dim dWidth As Double
  74.                 Dim dHeight As Double
  75.                 Dim pNewCentPt As Point2d
  76.  
  77.                 '' Check to see if a center point was provided (Center and Scale modes)
  78.                 If pCenter.DistanceTo(Point3d.Origin) <> 0 Then
  79.                     dWidth = acView.Width
  80.                     dHeight = acView.Height
  81.  
  82.                     If dFactor = 0 Then
  83.                         pCenter = pCenter.TransformBy(matWCS2DCS)
  84.                     End If
  85.  
  86.                     pNewCentPt = New Point2d(pCenter.X, pCenter.Y)
  87.                 Else '' Working in Window, Extents and Limits mode
  88.                     '' Calculate the new width and height of the current view
  89.  
  90.                     dWidth = eExtents.MaxPoint.X - eExtents.MinPoint.X
  91.                     dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y
  92.  
  93.                     '' Get the center of the view
  94.                     pNewCentPt = New Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5), ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5))
  95.                 End If
  96.  
  97.                 '' Check to see if the new width fits in current window
  98.                 If dWidth > (dHeight * dViewRatio) Then dHeight = dWidth / dViewRatio
  99.  
  100.                 '' Resize and scale the view
  101.                 If dFactor <> 0 Then
  102.                     acView.Height = dHeight * dFactor
  103.                     acView.Width = dWidth * dFactor
  104.                 End If
  105.  
  106.                 '' Set the center of the view
  107.                 acView.CenterPoint = pNewCentPt
  108.  
  109.                 '' Set the current view
  110.                 acDoc.Editor.SetCurrentView(acView)
  111.  
  112.             End Using
  113.  
  114.             '' Commit the changes
  115.             acTrans.Commit()
  116.         End Using
  117.  
  118.     End Sub
  119.  

Obviously you'd need to modify this principle to fit your needs,but i hope this approach helps you out doing so !

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #9 on: November 04, 2013, 09:13:54 AM »
Bert,

Thank you for the sample. Hopefully I can modify this to fit my routine. comments will really help here, thanks
it might take me a few days to get sample incorporated because of my lic issue so please understand if I can't post results right away.
You guys are the best!

Thanks
John

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #10 on: November 11, 2013, 07:16:41 PM »



All,

testing single zoom
test for right click collects the correct x,y, values from the datagridview2 and passes to zoom sub and the values for
point3d2 As Point3d are from the datagridview2 & correct values however I get an stack overflow error. any ideas 


Code: [Select]

Private Sub DataGridView2_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView2.MouseDown
        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument
        Dim acaddoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

        If e.Button = Forms.MouseButtons.Right Then
            Dim hi As DataGridView.HitTestInfo = Me.DataGridView2.HitTest(e.Location.X, e.Location.Y)
            MsgBox(Me.DataGridView2(6, hi.RowIndex).Value.ToString() + vbLf + Me.DataGridView2(7, hi.RowIndex).Value.ToString())

        Zoom(New Point3d(), New Point3d(), New Point3d(DataGridView2(6, hi.RowIndex).Value.ToString, DataGridView2(7, hi.RowIndex).Value.ToString, 0), 1)

        End If
    End Sub

    Public Sub Zoom(point3d As Point3d, point3d1 As Point3d, point3d2 As Point3d, p4 As Integer)

        Zoom(New Point3d(), New Point3d(), New Point3d(point3d2.X, point3d2.Y, 0), 1)
        Throw New NotImplementedException
    End Sub

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: datagridview right click get row/column values
« Reply #11 on: November 11, 2013, 07:20:35 PM »
 Where do you get it ? ... on which line.
Do you know what causes a stack overflow error?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: datagridview right click get row/column values
« Reply #12 on: November 11, 2013, 07:25:36 PM »
I don't have time to look at your code, but ..
A wild assed guess :
is the mouse event that fires this a single instance or does it keep running as long as you have the mouse down ..?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: datagridview right click get row/column values
« Reply #13 on: November 12, 2013, 09:15:56 AM »
is the mouse event that fires this a single instance or does it keep running as long as you have the mouse down ..?
Using the MouseDown event should normally be avoided, IMHO. Using the MouseClick or MouseUp events will all allow the same functionality without running into this possibility.

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #14 on: November 12, 2013, 11:34:34 AM »
Jeff,

Let me see if I can change this to what you recommend. until then this is the error I was getting, could it having an issue with the form loaded?

john


Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: datagridview right click get row/column values
« Reply #15 on: November 12, 2013, 01:22:18 PM »
John, your Zoom method is calling itself, thereby it is getting into an unending loop which is causing the stack overflow.

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #16 on: November 13, 2013, 12:05:15 PM »
Jeff_M,

Thanks.  Sorry I didn't respond,  I had a few rush items yesterday, Hopefully I can get time to correct that.

I think I know what's wrong with Vb dot net.....It makes people like me think......hey that would be nice to add.........fast-forward two or three days and 100 viewed web pages later and I'm posting here for help...........maybe I should of kept the routines plan-jane just like in the past.   oh well it's fun to try or at least see what is available that I can actually understand.

John

Bert

  • Guest
Re: datagridview right click get row/column values
« Reply #17 on: November 18, 2013, 09:58:37 AM »
Keep challenging yerself !

But like Jeff_M said, yer looping your code :

In my example its 'ZoomWindow' that calls 'Zoom' with a specific set of parameters.
Code - vb.net: [Select]
  1.     Public Shared Sub ZoomWindow(_pMin As Point3d, _pMax As Point3d)
  2.         '' Zoom to a window
  3.         Zoom(_pMin, _pMax, New Point3d(), 1)
  4.     End Sub
  5.  

jcoon

  • Newt
  • Posts: 157
Re: datagridview right click get row/column values
« Reply #18 on: December 02, 2013, 03:14:27 PM »
With a little time off for the holidays I was able to find time to work on this for a few days, with help from Fixo, Bert and through-the-interface I was able to get a working sample for now. currently working on test for button that cycles thru each row and does the same function as the right click but it needs a check for empty row value and highlight current row as visual for user.

thanks to all for sample & help
john


Private Sub DataGridView2_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView2.MouseDown
        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument
        Dim acaddoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

        If e.Button = Forms.MouseButtons.Right Then
            Dim hi As DataGridView.HitTestInfo = Me.DataGridView2.HitTest(e.Location.X, e.Location.Y)
            MsgBox(Me.DataGridView2(6, hi.RowIndex).Value.ToString() + vbLf + Me.DataGridView2(7, hi.RowIndex).Value.ToString())

            Dim passcell6 As Double
            Dim passcell7 As Double
            passcell6 = (Me.DataGridView2(6, hi.RowIndex).Value.ToString())
            passcell7 = (Me.DataGridView2(7, hi.RowIndex).Value.ToString())

            Dim zoomcorner1(0 To 1) As Double
            Dim zoomcorner2(0 To 1) As Double
            zoomcorner1(0) = passcell6 + 100
            zoomcorner1(1) = passcell7 + 100
            zoomcorner2(0) = passcell6 - 100
            zoomcorner2(1) = passcell7 - 100
            'x,y, location from grid
            Dim _pMin As Autodesk.AutoCAD.Geometry.Point2d = New Autodesk.AutoCAD.Geometry.Point2d(zoomcorner1)
            Dim _pMax As Autodesk.AutoCAD.Geometry.Point2d = New Autodesk.AutoCAD.Geometry.Point2d(zoomcorner2)
            Dim Min As Point2d
            Dim Max As Point2d
            Min = _pMin
            Max = _pMax
            ZoomWin(ed, Min, Max, True)
        End If
    End Sub

Private Shared Sub ZoomWin(ByVal ed As Editor, ByVal Min As Point2d, ByVal Max As Point2d, ByVal quietly As Boolean)
        Dim lower As String = Min.ToString.Substring(1, (Min.ToString.Length - 2))
        Dim upper As String = Max.ToString.Substring(1, (Max.ToString.Length - 2))
        Dim cmd As String = ("_.ZOOM _W " _
                    + (lower + (" " _
                    + (upper + " "))))
        If quietly Then
            ' Get the old value of NOMUTT
            Dim nomutt As Object = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("NOMUTT")
            ' Add the string to reset NOMUTT afterwards
            cmd = (cmd + ("_NOMUTT " _
                        + (nomutt.ToString + " ")))
            ' Set NOMUTT to 1, reducing cmd-line noise
            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("NOMUTT", 1)
        End If
        ' Send the command(s)
        ed.Document.SendStringToExecute(cmd, True, False, Not quietly)
    End Sub