FunctionX Practical Learning Logo

Data Navigation With Windows Controls



Although the records of a database are stored in tables, data sheets sometimes provide unfriendly environment for data entry. Of course, to avoid using database tables that can appear boring, you can use the DataGrid control. One of the characteristics of data grids is that they display all of their record set, or at least as much as their width and height can allow. If some fields require much room, a data grid as good looking as it can be, would not be suitable. Imagine that one of the columns contains fields of text of various paragraphs. In this case, the records should be displayed one at a time.

If you want to display one record at a time on a form, you can use Windows controls and provide a means for the user to navigate back and forth in the records.

Practical LearningPractical Learning: Display Data in Windows Controls

  1. Start Microsoft Visual Studio .Net and create a new Windows Forms Application named BCR2
  2. From the Server Explorer, expand the Servers node, the server that holds your SQL Server Installation, the SQL Servers node, and the name of the server you will be using
  3. Expand the BCR1 node and expand the Tables node
  4. Drag the CompanyAssets table and drop it on the form. You will receive a dialog box
  5. Click OK
  6. On the main menu, click Data -> Generate Dataset...
  7. Click the text box to the right of the New radio button and change it to dsCompAssets
  8. Click OK
  9. Click the Toolbox tab and click Windows Forms
  10. Design the form as follows:
    Control Name DataBindings -> Text
    dsCompAssets1 - CompanyAssets.
    Text Other Properties
    Form       Text: Company Assets
    Label     Asset Type:  
    TextBox txtAssetType AssetType    
    Label     Make:  
    TextBox txtMake Make  
    Label     Model:  
    TextBox txtModel Model  
    Label     Date Acquired:  
    TextBox txtDateAcquired DateAcquired    
    Label      Purchase Price:   
    TextBox txtPurchasePrice PurchasePrice   TextAlign: Right
    Label     Notes:  
    TextBox txtNotes Notes   Multiline: True
    ScrollBars: Vertical
    Button btnFirst   | <  
    Button btnPrevious   <  
    Button btnNext   >  
    Button btnLast   > |  
  11. Save the project
  12. Double-click an empty area on the form to access its Load event and implement it as follows:
    private void btnLoad_Click(object sender, System.EventArgs e)
  13. Double-click each of the buttons and implement them as follows:
    private void btnFirst_Click(object sender, System.EventArgs e)
    	this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position = 0;
    private void btnPrevious_Click(object sender, System.EventArgs e)
    	this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position = 
    		this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position - 1;
    private void btnNext_Click(object sender, System.EventArgs e)
    	this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position = 
    		this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position + 1;
    private void btnLast_Click(object sender, System.EventArgs e)
    	this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Position = 
    		this.BindingContext[this.dsCompAssets1, "CompanyAssets"].Count - 1;
  14. Test the application
  15. Close the form and the application

Home Copyright © 2004-2005 FunctionX, Inc.