Microsoft KB Archive/168835: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 68: Line 68:
       Thisform.OleControl1.Row=1
       Thisform.OleControl1.Row=1
       ThisForm.OleControl1.Col=1
       ThisForm.OleControl1.Col=1
       Thisform.Olecontrol1.Text="Test1"
       Thisform.Olecontrol1.Text="Test1"
       ThisForm.OleControl1.Row=1
       ThisForm.OleControl1.Row=1
       ThisForm.Olecontrol1.Col=2
       ThisForm.Olecontrol1.Col=2
       ThisForm.OleControl1.Text="Test2"
       ThisForm.OleControl1.Text="Test2"
       Thisform.OleControl1.Row=1 && Resets focus to first cell.
       Thisform.OleControl1.Row=1 && Resets focus to first cell.
       ThisForm.OleControl1.Col=1
       ThisForm.OleControl1.Col=1
Line 77: Line 77:
<li><p>Add three command buttons to the form and set the following properties and events as directed below: <span class="kbd userinput"> </span></p>
<li><p>Add three command buttons to the form and set the following properties and events as directed below: <span class="kbd userinput"> </span></p>
<pre class="codesample">      Command1
<pre class="codesample">      Command1
         Caption=&quot;Copy to Grid&quot;
         Caption="Copy to Grid"
         Click Event:
         Click Event:
         Thisform.OleControl1.Text=ThisForm.Text1.Value
         Thisform.OleControl1.Text=ThisForm.Text1.Value


       Command2
       Command2
         Caption=&quot;Copy From Grid&quot;
         Caption="Copy From Grid"
         ThisForm.Text1.Value=Thisform.OleControl1.Clip
         ThisForm.Text1.Value=Thisform.OleControl1.Clip


       Command3
       Command3
         Caption=&quot;Cut From Grid&quot;
         Caption="Cut From Grid"
         Click Event:
         Click Event:
         ThisForm.Text1.Value=ThisForm.OleControl1.Text
         ThisForm.Text1.Value=ThisForm.OleControl1.Text
         ThisForm.OleControl1.Text=&quot;&quot;
         ThisForm.OleControl1.Text=""
                             </pre></li>
                             </pre></li>
<li>Save the form and run it.</li>
<li>Save the form and run it.</li>
<li>Type &quot;Hello&quot; (without the quotes) in the text box and press &quot;Copy to Grid.&quot; The word &quot;Hello&quot; appears in the Grid control.</li>
<li>Type "Hello" (without the quotes) in the text box and press "Copy to Grid." The word "Hello" appears in the Grid control.</li>
<li>Click on the cell containing &quot;Test2&quot; with the mouse and then select &quot;Copy from Grid.&quot; &quot;Test2&quot; appears in the text box.</li>
<li>Click on the cell containing "Test2" with the mouse and then select "Copy from Grid." "Test2" appears in the text box.</li>
<li>Click on the cell containing &quot;Hello&quot; and select &quot;Cut From Grid.&quot; &quot;Hello&quot; appears in the text box and the contents of the first cell of the Grid control disappear.</li></ol>
<li>Click on the cell containing "Hello" and select "Cut From Grid." "Hello" appears in the text box and the contents of the first cell of the Grid control disappear.</li></ol>





Revision as of 11:03, 21 July 2020

Knowledge Base


How To Add Copy and Paste Functionality to Grid Control

Article ID: 168835

Article Last Modified on 6/29/2004



APPLIES TO

  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition



This article was previously published under Q168835

SUMMARY

When a Grid control object based on the Grid32.ocx is placed on a form, the cut, copy, and paste menu items are not available. Additionally, the hot keys, such as CTRL+V, do not function. This article shows how to use properties of the Grid control to emulate these editing functions.

MORE INFORMATION

Since neither the system menu options nor the shortcut keys for cut, copy, and paste work within the Grid control, the Grid32.OCX object properties must be used to accomplish these functions. To emulate these editing functions, the Clip, Col, Row, and Text properties of the Grid control must be used.

The example provided below uses a TextBox control and a Grid control to demonstrate how to copy, cut, and paste a text string between the two objects programmatically.

The following steps create a form containing a Grid control that has copy, cut, and paste functionality:

  1. Create a form and place a TextBox and an OLE Container Control on it.
  2. In the OLE Container Control, click Insert Control and choose the Grid Control object.
  3. Right-click the Grid control and choose Grid properties. Click the General tab and change both the Row and Col properties to 3 and click Apply.
  4. In the Init of the form, place the following code:

           ** This code places text values in the Grid object **
           Thisform.OleControl1.Row=1
           ThisForm.OleControl1.Col=1
           Thisform.Olecontrol1.Text="Test1"
           ThisForm.OleControl1.Row=1
           ThisForm.Olecontrol1.Col=2
           ThisForm.OleControl1.Text="Test2"
           Thisform.OleControl1.Row=1 && Resets focus to first cell.
           ThisForm.OleControl1.Col=1
                                
  5. Add three command buttons to the form and set the following properties and events as directed below:

           Command1
            Caption="Copy to Grid"
            Click Event:
            Thisform.OleControl1.Text=ThisForm.Text1.Value
    
           Command2
            Caption="Copy From Grid"
            ThisForm.Text1.Value=Thisform.OleControl1.Clip
    
           Command3
            Caption="Cut From Grid"
            Click Event:
            ThisForm.Text1.Value=ThisForm.OleControl1.Text
            ThisForm.OleControl1.Text=""
                                
  6. Save the form and run it.
  7. Type "Hello" (without the quotes) in the text box and press "Copy to Grid." The word "Hello" appears in the Grid control.
  8. Click on the cell containing "Test2" with the mouse and then select "Copy from Grid." "Test2" appears in the text box.
  9. Click on the cell containing "Hello" and select "Cut From Grid." "Hello" appears in the text box and the contents of the first cell of the Grid control disappear.


REFERENCES

For additional information on the properties of the Grid control, invoke the Visual Basic Help file by clicking the Grid control and pressing the F1 key.

Keywords: kbhowto KB168835