Propertgrid and Datalink dialog

  • Thread starter Thread starter hazz
  • Start date Start date
H

hazz

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
 
hazz said:
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

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;
}

}
 
Thank you very much for your timely reply Nadav ! I am evaluating your two
classes right now.
Appreciatively,
-Greg

"hazz" <[email protected]> wrote in message
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

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.UITypeEdito
r))]

(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.UITypeEdito
r))]
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;
}

}
 
Nadav,
The developer who asked me to post his question says your code was
successful in solving his problem.
THANK YOU.
-greg

"hazz" <[email protected]> wrote in message
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

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.UITypeEdito
r))]

(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.UITypeEdito
r))]
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;
}

}
 
Back
Top