See the example of VFP: Delete records in a datasheet

Source: Internet
Author: User

This example is to look at the case of VFP: The record in the data table to modify the example of the article made a little improvement, adding the "undo" function. When the program is run, the following figure:

Select the field you want to find in the combo box, click the Find button on the right after you enter the lookup in the text box, and then the Find button changes to the Undo button, activating the Delete button and the text box used to display the data. and displays the value of the current record (the record that satisfies the query condition) in the text box at the same time; Clicking the Delete button deletes the found record refresh display and grid1, the Delete button is disabled again, and the Undo button's caption value becomes find again and hides the text box that displays the data; The Undo button undoes the deletion and refreshes the form. The following figure:

About VFP table record pointer positioning and data sorting please refer to: Record pointer positioning and data ordering, about record deletion please refer to the table's operation (b), this example uses the "Data 1" database "website Information table", about the situation of the database is already looking at the case of VFP: sample database is given in the article, Here are no longer detailed, only a brief introduction to the production process.

The production steps are as follows:

First, create a new form Form1 and set its Caption property to delete records in datasheet, set the Width property value to the 290,height property value set to the 220,autocenter property value set to. T, and save it as "delete records from datasheet. Scx".

Add a Grid control to the form, set its ReadOnly property to. T, and its recordsourcetype value with the default "1-alias", and in the form designer, width and height, and then roughly lower it, Specific attribute values we will set them in the form's Init event code.

Third, add two label controls below the grid control, line them in one row, and set their Caption property to "Select Find how" and "Enter what you want to find."

Four, add a combo box control below the label control Combo1 and a text box control Text1, the text box control's property value is the default, the combo box control Combo1 's RowSourceType property value is set to "N", and the RowSource property value is set to " Number, website name, website url "so that at runtime we can select the fields to query in the combo box.

Five, add two command buttons Command1 and Command2 on the form, and set their caption properties to find and delete.

Six, add three label controls below the command button, line the three label controls, and set their Caption property to number, site name, and site URL.

Seven, add three text box controls below this line of label controls, the property values are default, and the three text boxes are lined up in one line.

Eight, adjust the position of the controls on the form, and the Adjusted form designer follows the following figure:

Nine, add the event code:

(i) Unload event code for the form:

Set Exact off
Close data

(ii) The Init event code for the form:

Set exact on
set Delete off
set safe off
this.command2.enabled=.f.
This. Text2.visible=.f.
This. Text3.visible=.f.
This. Text4.visible=.f.
This. Label3.visible=.f.
This.label4.visible=.f.
This. Label5.visible=.f.
Use Web site information table this
. Combo1.value= "numbered" with Thisform.grid1. width=350. height=100 left=0.
  top=0
  . Recordsource= "website Information table"
  . Deletemark=.f.
  visible=.t..
  readonly=.t..
  Columncount=3
  . column1.header1.caption= "Number"
  . Column1.header1.backcolor=rgb (255,255,190)
  . Column2.header1.backcolor=rgb (255,255,190)
  . column2.header1.caption= "website name"
  . Column3.header1.backcolor=rgb (255,255,190)
  . column3.header1.caption= "website url"
  . Column1.width=75
  . Column2.width=80
  . column3.width=150
endwith
this.grid1.Setall ("Dynamicbackcolor", "RGB (224,225,255)", "Column")

(iii) Click event code for the Find button (Command1):

If this.caption= "Find" if Empty (thisform.
 Text1.value) =.f. Go top A=thisform.combo1.value B=alltrim (thisform.
  Text1.value) c=.f. 
      If a= "numbered" Locate for number =b if EOF () MessageBox ("The record you want to query does not exist in the database", 16, "System Prompt") go
     Else c=.t. endif endif if a= "site name" locate for Site name =b if EOF () MessageBox ("The record you want to query does not exist in the database", 16, "system hint") g
     o Top return else c=.t. endif endif if a= "website url" Locate for Web site =b if EOF () MessageBox ("The record you want to query does not exist in the database", 16, "system hint") g
     o Top return else c=.t. endif endif if C go recno () thisform.
     Text1.enabled=.f. Thisform.
     text2.visible=.t. Thisform.
     text3.visible=.t. Thisform.
     text4.visible=.t. Thisform.
     Text2.enabled=.f. Thisform.
     Text3.enabled=.f. Thisform.
     Text4.enabled=.f. Thisform.
     label3.visible=.t.
     thisform.label4.visible=.t. Thisform.
     label5.visible=.t. ThisfoRm. Text2.value= Web site Information table. Thisform number. Text3.value= Web site Information table. The website name Thisform.
  Text4.value= Web site Information table Thisform.grid1.setfocus this.caption= "undo" thisform.command2.enabled=.t. endif Else MessageBox ("Please enter the content you want to find!") ", 16," system hint ") thisform. Text1.value= "" Thisform. Text1.setfocus endif Else thisform.
 text1.enabled=.t. Thisform.
 Text2.visible=.f. Thisform.
 Text3.visible=.f. Thisform.
 Text4.visible=.f. Thisform.
 Text2.enabled=.f. Thisform.
 Text3.enabled=.f. Thisform.
 Text4.enabled=.f. Thisform.
 Label3.visible=.f.
 Thisform.label4.visible=.f. Thisform.
 Label5.visible=.f. Thisform. Text2.value= "" Thisform. Text3.value= "" Thisform.
 Text4.value= "" Thisform.grid1.setfocus this.caption= "Find" thisform.command2.enabled=.f. Go top Thisform.grid1.setfocus thisform. Text1.value= "" Thisform. Text1.setfocus endif Thisform.refresh

(iv) Click event code for the Delete button (Command2):

Msg=messagebox (' Are you sure you want to delete this record?] ', 32+4, ' system hint ')
if msg=6 
   delete
   copy to temp.dbf for Don't deleted ()
   zap
   Append from temp.dbf
   Delete file temp.dbf
   MessageBox ("Delete record succeeded", 16, "System Prompt") go top
   thisform.grid1.refresh
   Thisform.command1.caption= "Find"
   this.enabled=.f.
   Thisform. Text2.visible=.f.
   Thisform. Text3.visible=.f.
   Thisform. Text4.visible=.f.
   Thisform. Label3.visible=.f.
   Thisform.label4.visible=.f.
   Thisform. Label5.visible=.f. 
   Thisform. text1.enabled=.t.  
   Thisform. Text1.value= ""
   thisform. Text1.setfocus
   Thisform.refresh
endif

Run "delete the records in the datasheet. Scx".

Resources:

The basic course of VFP: http://bianceng.cnhttp://www.bianceng.cn/vfpjc/index0.htm

VFP Primary Course: http://bianceng.cnhttp://www.bianceng.cn/cc/index.htm

VFP Intermediate Course: http://bianceng.cnhttp://www.bianceng.cn/mcc/mcc.htm

VFP Advanced Course: http://bianceng.cnhttp://www.bianceng.cn/hcc/hcc.htm

VFP Network Development: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpwlkf.htm

VFP Call API function: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpapi.htm

VFP Report Print: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpreport.htm

VFP Common technique: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpcyjs.htm

VFP Experience Summary: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpjyhz.htm

VFP Control use: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpkjsy.htm

VFP Data processing: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpsjcl.htm

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.