Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Oliver Cortazar
  Where is Oliver Cortazar?
 San Luis Potosi
 Mexico
 Oliver Cortazar
 Tags
Subject: RE: VFPToolkitNET browse form
Thread ID: 228707 Message ID: 228905 # Views: 2 # Ratings: 1
Version: Not Applicable Category: .NET
Date: Friday, May 22, 2009 2:32:45 PM         
   


> You are right, it is very simple. I'll just have to sink my nose in the books and tutorials to learn more.
>
> I don't mean to be a bother, but could you add the code in the class ShowDataForm to release the form when you press either ESC or RETURN? It would save me a lot of research time.
>
> I'll be also picking your brain reading your blog. I liked it very much. The first entry erased my doubth about .NET.
>
> Thank you very much.

using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Collections;
using System.Linq;
using System.IO;

class sample
{
 static void Main()
 {
   DataTable tbl = new DataTable();
   OleDbConnection cn = new OleDbConnection(
     "Provider=VFPOLEDB;Data Source="+
  @"C:\Program Files\Microsoft Visual FoxPro 9\Samples\Data\testdata.dbc");
   cn.Open();
   OleDbDataReader rdr = new OleDbCommand("select * from customer", cn).ExecuteReader();
   tbl.Load(rdr);
   cn.Close();
   
   // table
   Form f = new ShowDataForm(tbl);
   f.ShowDialog();

   System.Diagnostics.Process[] runningProcesses = 
         System.Diagnostics.Process.GetProcesses();

   // running system processes
   f = new ShowDataForm(runningProcesses);
   f.ShowDialog();

   // files
   DirectoryInfo di = new DirectoryInfo(@"c:\Program Files\Microsoft Visual FoxPro 9");
   string[] extensions = { ".scx", ".prg" };

   var files = from myFile in di.GetFiles("g*.*",SearchOption.AllDirectories)
               where extensions.Contains(myFile.Extension.ToLower())
               select myFile;

   f = new ShowDataForm( files.ToArray() );
   f.ShowDialog();

 }
}

public class ShowDataForm : Form
{
  public ShowDataForm(object o)  
  {
     this.ClientSize = new System.Drawing.Size(1024, 768);
     this.dgv = new System.Windows.Forms.DataGridView();
     this.dgv.DataSource = o;
     this.dgv.Dock = DockStyle.Fill;
     this.Controls.Add(this.dgv);
     
     // "delegate"ing KeyDown of dgv object to "this"form's method named "MyMethodThatShouldRunWhenKeyDownOnDataGridView"
     this.dgv.KeyDown += new KeyEventHandler( this.MyMethodThatShouldRunWhenKeyDownOnDataGridView );
  }

  // this is the code to handle KeyDown event of DataGridView
  // typical naming is objectName_EventName. ie: dgv_KeyDown
  // Here I intentionally gave a long and different name
  // to give an idea about "delegate" and "event"s which maybe is the most confusing topic
  // of C#
  private void MyMethodThatShouldRunWhenKeyDownOnDataGridView(object sender, KeyEventArgs e)
  {
    if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape)
    {
       e.Handled = true;
       this.Close(); // close the form 
     }
  }
  private DataGridView dgv;
}


Also there is some explanation about delegates on my blog, but this is the general structure for handling form events ( + to add event "handler code", - to subtract).
Glad you liked blog:) There is no mention of new cool 2010 features there yet, will be if time lets me to write.

Cetin Basoz

.Net has got better.Think about moving - check my blog:
Blog (main)
Blog (mirror)

ENTIRE THREAD

VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/21/2009 12:36:05 AM
RE: VFPToolkitNET browse form Posted by Cetin Basoz @ 5/21/2009 1:45:36 PM
RE: VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/21/2009 8:09:47 PM
RE: VFPToolkitNET browse form Posted by Cetin Basoz @ 5/21/2009 10:59:56 PM
RE: VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/22/2009 12:58:26 AM
RE: VFPToolkitNET browse form Posted by Cetin Basoz @ 5/22/2009 2:32:45 PM
RE: VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/22/2009 6:56:08 PM
RE: VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/22/2009 9:33:50 PM
RE: VFPToolkitNET browse form Posted by Cetin Basoz @ 5/23/2009 12:29:46 PM
RE: VFPToolkitNET browse form Posted by Christian Tabligan @ 5/21/2009 1:58:58 PM
RE: VFPToolkitNET browse form Posted by Oliver Cortazar @ 5/21/2009 8:13:55 PM
RE: VFPToolkitNET browse form Posted by Tom Saddul @ 5/23/2009 5:23:39 AM
RE: VFPToolkitNET browse form Posted by Boudewijn Lutgerink @ 5/25/2009 8:46:22 AM