Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Propertgrid and Datalink dialog

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hazz - 13 Sep 2004 23:24 GMT
Hi All,

I'm trying to open a Datalink property dialog from Propertygrid. So that i
can update connection string in my app.config file. If someone can help me
or give some pointers i will be greateful.

Thanks....
Greg
nadavp@bac-soft.com - 14 Sep 2004 10:57 GMT
> Hi All,
>
[quoted text clipped - 4 lines]
> Thanks....
> Greg

Try the following Code, It works for me...

This code defined two classes:

ADOConnectionDialog - a component that use can add to the visual
studio toolbox and use like OpenFileDialog.
ADOConnectionEditor - an editor that is used to edit the
ConnectionString in the propertygrid.
to use it just mark your ConnectionString property with this
attributes:
[Browsable(true)]
[Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEditor))]

(see ADOConnectionDialog.ConnectionString property)

Hope this helps
Nadav

P.S. to use this code you have to add a reference to
System.Drawing.Design assembly.

--- source code follows: ---

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;

using System.Drawing.Design;

    /// <summary>
    /// Summary description for ADOConnectionDialog.
    /// </summary>
    public class ADOConnectionDialog : System.ComponentModel.Component {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        /// <summary>
        ///
        /// </summary>
        /// <param name="container"></param>
        public ADOConnectionDialog(System.ComponentModel.IContainer
container) {
            ///
            /// Required for Windows.Forms Class Composition Designer support
            ///
            container.Add(this);
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        ///
        /// </summary>
        public ADOConnectionDialog() {
            ///
            /// Required for Windows.Forms Class Composition Designer support
            ///
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if(components != null) {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        private string _ConnectionString="";

        /// <summary>
        ///
        /// </summary>
        [Browsable(true)]
        [Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
        public string ConnectionString {
            get { return _ConnectionString; }
            set { _ConnectionString=value; }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public DialogResult ShowDialog(ref string ConnectionString )
{
            MSDASC.DataLinks mydlg = new MSDASC.DataLinks();
            ADODB._Connection adoCon=null;
            if (ConnectionString==null || ConnectionString=="") {
                adoCon=(ADODB._Connection)mydlg.PromptNew();
            } else {
                adoCon=new ADODB.ConnectionClass();
                adoCon.ConnectionString=ConnectionString;
                object x=adoCon;
                if (mydlg.PromptEdit(ref x)) {
                    adoCon=x as ADODB._Connection;
                }
            }
            if (adoCon==null) {
                return DialogResult.Cancel;
            } else {
                ConnectionString=adoCon.ConnectionString;
                return DialogResult.OK;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual DialogResult ShowDialog() {
            return ADOConnectionDialog.ShowDialog(ref _ConnectionString);
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            components = new System.ComponentModel.Container();
        }
        #endregion
    }
   
    /// <summary>
    ///
    /// </summary>
    public class ADOConnectionEditor : System.Drawing.Design.UITypeEditor
{
        /// <summary>
        ///
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override System.Object EditValue (
System.ComponentModel.ITypeDescriptorContext context ,
System.IServiceProvider provider , System.Object value ) {
            string ConnectionString=(value==null)?"":value.ToString();
            if (ADOConnectionDialog.ShowDialog(ref
ConnectionString)==DialogResult.OK) {
                return ConnectionString;
            } else {
                return value;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override System.Drawing.Design.UITypeEditorEditStyle
GetEditStyle ( System.ComponentModel.ITypeDescriptorContext context )
{
            return UITypeEditorEditStyle.Modal;
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override bool GetPaintValueSupported(
System.ComponentModel.ITypeDescriptorContext context ) {
            return false;
        }

    }
hazz - 14 Sep 2004 15:44 GMT
Thank you very much for your timely reply Nadav !  I am evaluating your two
classes right now.
Appreciatively,
-Greg

> > Hi All,
> >
[quoted text clipped - 16 lines]
> attributes:
> [Browsable(true)]

[Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEdito
r))]

> (see ADOConnectionDialog.ConnectionString property)
>
[quoted text clipped - 72 lines]
> /// </summary>
> [Browsable(true)]

[Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEdito
r))]
> public string ConnectionString {
> get { return _ConnectionString; }
[quoted text clipped - 89 lines]
>
> }
hazz - 15 Sep 2004 14:27 GMT
Nadav,
The developer who asked me to post his question says your code was
successful in solving his problem.
THANK YOU.
-greg

> > Hi All,
> >
[quoted text clipped - 16 lines]
> attributes:
> [Browsable(true)]

[Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEdito
r))]

> (see ADOConnectionDialog.ConnectionString property)
>
[quoted text clipped - 72 lines]
> /// </summary>
> [Browsable(true)]

[Editor(typeof(ADOConnectionEditor),typeof(System.Drawing.Design.UITypeEdito
r))]
> public string ConnectionString {
> get { return _ConnectionString; }
[quoted text clipped - 89 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.