1. Create an MDI parent form and insert menu with Open and New. 2. Create another form as MDIChild with a TreeView control in it.(Refer my previous article of How to populate a TreeView control from an Access database....! ) 3. On menuOpen_Click event add the given codes....
private void menuFileOpen_Click(object sender, System.EventArgs e) { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "DataBase Files (*.mdb)|*.mdb"; openDlg.FileName = "" ; openDlg.DefaultExt = ".mdb"; openDlg.CheckFileExists = true; openDlg.CheckPathExists = true;
DialogResult res = openDlg.ShowDialog (); if(res == DialogResult.OK) { if ( ! ( openDlg.FileName ).EndsWith(".mdb") && ! ( openDlg.FileName ).EndsWith (".MDB") ) MessageBox.Show( "Invalid file format...!" , "Prajeesh" , MessageBoxButtons.OK , MessageBoxIcon.Exclamation ) ;
else { TreeView tree = new TreeView(); tree.Close(); //ActiveMdiChild.Close();
DatabaseName = openDlg.FileName; //Initialises the connection with the database with the datasource as "DatabaseName" TreeViewLoad( DatabaseName ); } } ::--::--::::--::--::::--::--::::--::--::::--::--::::--::--:: public void TreeViewLoad(string dbName) { TreeView tree = new TreeView(); //passes the DatabaseName to the TreeView class. tree.DatabaseName = dbName; tree.MdiParent = this; tree.Show(); }
::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::::--::
5. Create a template database as a source. 4. On menuNew_Click event add the given codes....
SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "Database File (*.mdb)|*.mdb" ; saveFileDlg.Title = "Create New Database"; saveFileDlg.RestoreDirectory = false; if(saveFileDlg.ShowDialog() == DialogResult.OK) { TreeView tree = new TreeView(); // Template database path string sourceFile = @"C:\prajeesh\My Documents\\SampleProject\Template.mdb"; DatabaseName = saveFileDlg.FileName; try { File.Copy ( sourceFile , DatabaseName ) ; TreeViewLoad ( DatabaseName ); } catch ( Exception ex ) { MessageBox.Show( ex.Message ) ; } }
:--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::::--::--:: In the TreeView class you can do the following on form load event Initialises the database connection
private string Provider = "Microsoft.Jet.OLEDB.4.0"; private string User = "Admin"; private string Password = ""; private string Mode = "ReadWrite"; public string DatabaseName;
private void TreeView_Load(object sender, System.EventArgs e) { this.dbConnection = new System.Data.OleDb.OleDbConnection(); StringBuilder strBuild = new StringBuilder(); strBuild.AppendFormat( "Provider={0};Password=\"{1}\";User ID={2};Data Source={3};Mode={4}", Provider, Password, User, DatabaseName, Mode ); dbConnection2.ConnectionString = strBuild.ToString(); }
Refer my previous article to continue with the populating part!!.... More articles coming up soon..... Until then....Happy Coding Regards, Prajeesh :-)
|
| Author: critic 14 Jun 2004 | Member Level: Bronze Points : 0 |
I is a reasonably good article.. but in the space provided to enter all used .NET classes, you have simply given the namespaces !!
|
| Author: SAM 14 Jul 2004 | Member Level: Bronze Points : 0 |
Hi Prajeesh:
Do you have this code in VB.NET?
RGDS Sam
|
| Author: zxn 12 Apr 2005 | Member Level: Bronze Points : 0 |
thanks
|
| Author: Biju Samuel 13 Apr 2005 | Member Level: Bronze Points : 0 |
I want to save a file to pdf format. pls give me the code.in c#
|
| Author: Varsha 27 Aug 2008 | Member Level: Bronze Points : 0 |
Can you send this code in Vb.net
|