Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSHFlexGrid click cell and copy to clipboard 2

Status
Not open for further replies.

EchoAlertcom

IS-IT--Management
Joined
Oct 8, 2002
Messages
239
Location
US
Hello,

I am very new with VB6 so I would appreciate an expample that a beginner can understand.

I have an MSHFlexGrid. When a user clicks on a cell I would like the contents of that specific cell copied to the windows clipboard.

Thank you for your help.

Sincerely,
Steve
 
Try this, where fg1 is the name of the Flexgrid:

Private Sub fg1_EnterCell()
Clipboard.Clear
Clipboard.SetText fg1.Text
End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks, That worked great.

One of my fields in the FlexGrid is a URL.

Is there a way that when the cell in URL Column is right-clicked that it will open a browser to that URL?

Thank you again for the help./

Sincerely,
Steve
 
I would use the MouseDown event of the grid, and then check which button was pressed to trigger the process.

You have at least two options with respect to the loading the web page:

1) Add the Microsoft Internet Control to the project, and then in code, perform the following:
Code:
Dim lWebBrowse As InternetExplorer
Set lWebBrowse = New InternetExplorer
lWebBrowse.Stop
lWebBrowse.Visible = True
lWebBrowse.Navigate (fg1.Text)
Be sure to set the lWebBrowse object to nothing when you're done.

2) The second option is to use the ShellExecute API call, with the URL as the 2nd arguement.
Delcare the API
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Private Const SW_SHOW = 3
and then in the routine
Code:
ShellExecute hWnd, "open", fg1.Text;, vbNullString, vbNullString, SW_SHOW
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi,

That worked great too. Thank you. This is really coming together.

One thing I would like to do is only allow this to happen on a specific column in the grid. In other words, only one column lists the URL. I don't want IE to open on any other column. Just the the fouth column. I assume I need an IF statement that says IF Column = URL then "the code posted above. I would need help in how to do this.

Thanks to everyone for your help.

Sincerely,
Steve
 
I'm afraid you're going to need a little more than an IF statement because the MouseDown returns the position of the mouse within the grid as a coordinate, but is not directly associated with any particular column. What you can do is to check the X parameter value for the event, and see if it lies within the column that contains the URL.
Code:
Private Sub fg1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

   Dim CurrCol as Integer

   If (Button = 2) Then         ' Right Mouse Button
      With fg1                  ' Set Object Reference
         .Redraw = False        ' Don't want visble feedback 
         CurrCol = .Col         ' Keep track of current column
         .Row = .FixedRows      ' Any Non-Merged Row will do
         .Col = 6               ' This is the URL Column
                                ' Check if inside the URL column
         If ((x >= .CellLeft) And (x <= .CellLeft + .CellWidth - 1)) Then 
            CurrCol = .Col      ' Update the Current Column to the URL Col
            MsgBox &quot;Trigger the URL&quot;   ' Trigger the Page
         End If
         .Col = CurrCol         ' Return to Current Column
         .Redraw = True         ' Turn the Draw Back on
      End With
   End If
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi CajunCenturion

I replaced your messagebox for the code that you gave me earlier (that worked fine in the Private Sub MSHFlexGrid1_Click() just happened with every cell
&quot;
Dim lWebBrowse As InternetExplorer

Set lWebBrowse = New InternetExplorer
lWebBrowse.Stop
lWebBrowse.Visible = True
lWebBrowse.Navigate (MSHFlexGrid1.Text)

After I set this up nothing happens when I right-click (or left-click when I changed 2 to 1.

Here is the code as I have it:

Code:
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'-------------------------------------------------------------------------------------------
' code in grid's DragDrop, MouseDown, MouseMove, and MouseUp events enables column dragging
'-------------------------------------------------------------------------------------------

   If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
   If MSHFlexGrid1.MouseCol = 0 And MSHFlexGrid1.FixedCols = 1 Then Exit Sub

   xdn = x
   ydn = y
   m_iDragCol = -1      ' clear drag flag
   m_bDragOK = True
   
   'Start of your code
   Dim CurrCol As Integer

   If (Button = 1) Then         ' Right Mouse Button
      With MSHFlexGrid1         ' Set Object Reference
         .Redraw = False        ' Don't want visble feedback
         CurrCol = .Col         ' Keep track of current column
         .Row = .FixedRows      ' Any Non-Merged Row will do
         .Col = 3               ' This is the URL Column
                                ' Check if inside the URL column
         If ((x >= .CellLeft) And (x <= .CellLeft + .CellWidth - 1)) Then
            CurrCol = .Col      ' Update the Current Column to the URL Col
            ' Trigger the Page
            Dim lWebBrowse As InternetExplorer
   
            Set lWebBrowse = New InternetExplorer
            lWebBrowse.Stop
            lWebBrowse.Visible = True
            lWebBrowse.Navigate (MSHFlexGrid1.Text)
         End If
         .Col = CurrCol         ' Return to Current Column
         .Redraw = True         ' Turn the Draw Back on
      End With
   End If

End Sub

Nothing happens. Not even an debug error.

Thank you so much for your help. You have answered some of my questions in the past and are always successful in getting me through.

Sincerely,
Steve
 
Two things - I was not familiar with the MouseRow and MouseCol properties of the Grid, I need to look into those.

With respect to the code, the one thing that stands out is the IF conditional

You have If (Button = 1) ' Left Button
Shouble be If (Button = 2) ' Right Button

Will get back to you on the MouseRow and MouseCol. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
OK, Two things, the problem with the code that I posted is that it was not taking into the account the proper row, and secondly, the line that you added
Code:
If MSHFlexGrid1.MouseRow <> 0 Then Exit Sub
will cause the sub to exit except when MouseRow is 0. The good news is that you can throw it all away anyway as the MouseRow and MouseCol properties do exactly what we want them to do.
Code:
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
   
   If (Button = 2) Then
      With MSHFlexGrid1
         If (.MouseRow >= .FixedRows) Then
            If (.MouseCol = 3) Then
               .Row = .MouseRow
               .Col = .MouseCol
               Dim lWebBrowse As InternetExplorer
      
               Set lWebBrowse = New InternetExplorer
               lWebBrowse.Stop
               lWebBrowse.Visible = True
               lWebBrowse.Navigate (.Text)
            End If
         End If
      End With
   End If
   
End Sub
And for bringing to my attention the additional properties of the FlexGrid, properties that I do find helpful, I thank you. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I know it's not as elegant but....

Add a webbrowser control (wb1) then use:
Private Sub fg1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 2 And fg1.MouseCol = 2 Then
wb1.Navigate (fg1.TextMatrix(fg1.MouseRow, fg1.MouseCol))
End If
End Sub

where fg1 is the name of your flexgrid
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top