Collection Editor for my Custom Control 
Author Message
 Collection Editor for my Custom Control

Hy!

I made a Costom Control in which I got a Property called Column. The type of
this Property is ColumnCollection. To entry values Ive made a class called
ColumnEditor which is derived from CollectionEditor.
The following problem occurs. I can change the property in my editor and the
value is shown in my control. But only if I resize the UserControl with the
mous ma Custom Code is implemented in the InitializeComponent Functiobn of
my form.

What am I doin wrog here.

Beyond I got the code of my editor.
Please help me.

Ronny

#region Column Editor

//public class ColumnEditor : UITypeEditor

public class ColumnEditor : System.ComponentModel.Design.CollectionEditor

{

private IWindowsFormsEditorService edSvc = null;

public ColumnEditor(): base(typeof(GridControlXColumn))

{

Quote:
}

#region Column Form Class

class ColumnForm:
System.ComponentModel.Design.CollectionEditor.CollectionForm

{

#region Fields

private System.Windows.Forms.ListView listViewColumns;

private System.Windows.Forms.ColumnHeader columnHeaderCols;

private System.ComponentModel.Container components = null;

private System.Windows.Forms.PropertyGrid propertyGrid;

private GridControlX MyControl;

private System.Windows.Forms.Button buttonDeleteColumn;

private System.Windows.Forms.Button buttonAddColumn;

private System.Windows.Forms.Button buttonCancel;

private System.Windows.Forms.Panel panel1;

private System.Windows.Forms.ComboBox comboBoxColumnStyle;

private GridControlXColumn SelectedColumn = null;

private ColumnCollection myCollection = new ColumnCollection();

private ColumnCollection myDelCollection = new ColumnCollection();

private System.Windows.Forms.Button buttonOk;

private ColumnEditor editor;

#endregion

public ColumnForm(CollectionEditor editor, GridControlX myInstance) :
base(editor)

{

this.editor = (ColumnEditor)editor;

this.MyControl = myInstance;

InitializeComponent();

this.AddColumnsToList();

this.InitComboBox();

Quote:
}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

Quote:
}
}

base.Dispose( disposing );

Quote:
}

protected override void OnEditValueChanged()

{

Quote:
}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.listViewColumns = new System.Windows.Forms.ListView();

this.columnHeaderCols = new System.Windows.Forms.ColumnHeader();

this.propertyGrid = new System.Windows.Forms.PropertyGrid();

this.buttonDeleteColumn = new System.Windows.Forms.Button();

this.buttonAddColumn = new System.Windows.Forms.Button();

this.buttonCancel = new System.Windows.Forms.Button();

this.panel1 = new System.Windows.Forms.Panel();

this.comboBoxColumnStyle = new System.Windows.Forms.ComboBox();

this.buttonOk = new System.Windows.Forms.Button();

this.panel1.SuspendLayout();

this.SuspendLayout();

//

// listViewColumns

//

this.listViewColumns.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[] {

this.columnHeaderCols});

this.listViewColumns.Dock = System.Windows.Forms.DockStyle.Left;

this.listViewColumns.Font = new System.Drawing.Font("Microsoft Sans Serif",
7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));

this.listViewColumns.FullRowSelect = true;

this.listViewColumns.HideSelection = false;

this.listViewColumns.Name = "listViewColumns";

this.listViewColumns.Size = new System.Drawing.Size(248, 486);

this.listViewColumns.TabIndex = 0;

this.listViewColumns.View = System.Windows.Forms.View.Details;

this.listViewColumns.SelectedIndexChanged += new
System.EventHandler(this.listViewColumns_SelectedIndexChanged);

//

// columnHeaderCols

//

this.columnHeaderCols.Text = "Columns";

this.columnHeaderCols.Width = 250;

//

// propertyGrid

//

this.propertyGrid.CommandsVisibleIfAvailable = true;

this.propertyGrid.Dock = System.Windows.Forms.DockStyle.Right;

this.propertyGrid.LargeButtons = false;

this.propertyGrid.LineColor = System.Drawing.SystemColors.ScrollBar;

this.propertyGrid.Location = new System.Drawing.Point(258, 0);

this.propertyGrid.Name = "propertyGrid";

this.propertyGrid.Size = new System.Drawing.Size(280, 486);

this.propertyGrid.TabIndex = 8;

this.propertyGrid.Text = "propertyGrid";

this.propertyGrid.ViewBackColor = System.Drawing.SystemColors.Window;

this.propertyGrid.ViewForeColor = System.Drawing.SystemColors.WindowText;

this.propertyGrid.PropertyValueChanged += new
System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid_Prop
ertyValueChanged);

//

// buttonDeleteColumn

//

this.buttonDeleteColumn.Location = new System.Drawing.Point(120, 16);

this.buttonDeleteColumn.Name = "buttonDeleteColumn";

this.buttonDeleteColumn.Size = new System.Drawing.Size(96, 24);

this.buttonDeleteColumn.TabIndex = 3;

this.buttonDeleteColumn.Text = "&Del Column";

this.buttonDeleteColumn.Click += new
System.EventHandler(this.buttonDeleteColumn_Click);

//

// buttonAddColumn

//

this.buttonAddColumn.Location = new System.Drawing.Point(8, 16);

this.buttonAddColumn.Name = "buttonAddColumn";

this.buttonAddColumn.Size = new System.Drawing.Size(96, 24);

this.buttonAddColumn.TabIndex = 2;

this.buttonAddColumn.Text = "&Add Column";

this.buttonAddColumn.Click += new
System.EventHandler(this.buttonAddColumn_Click);

//

// buttonCancel

//

this.buttonCancel.Location = new System.Drawing.Point(432, 48);

this.buttonCancel.Name = "buttonCancel";

this.buttonCancel.Size = new System.Drawing.Size(96, 24);

this.buttonCancel.TabIndex = 1;

this.buttonCancel.Text = "&Cancel";

this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);

//

// panel1

//

this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {

this.comboBoxColumnStyle,

this.buttonDeleteColumn,

this.buttonAddColumn,

this.buttonCancel,

this.buttonOk});

this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;

this.panel1.Location = new System.Drawing.Point(0, 486);

this.panel1.Name = "panel1";

this.panel1.Size = new System.Drawing.Size(538, 80);

this.panel1.TabIndex = 9;

//

// comboBoxColumnStyle

//

this.comboBoxColumnStyle.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;

this.comboBoxColumnStyle.Location = new System.Drawing.Point(8, 48);

this.comboBoxColumnStyle.Name = "comboBoxColumnStyle";

this.comboBoxColumnStyle.Size = new System.Drawing.Size(208, 24);

this.comboBoxColumnStyle.TabIndex = 4;

//

// buttonOk

//

this.buttonOk.Location = new System.Drawing.Point(320, 48);

this.buttonOk.Name = "buttonOk";

this.buttonOk.Size = new System.Drawing.Size(96, 24);

this.buttonOk.TabIndex = 5;

this.buttonOk.Text = "&Ok";

this.buttonOk.Click += new System.EventHandler(this.OnOkClick);

//

// ColumnEditorForm

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);

this.ClientSize = new System.Drawing.Size(538, 566);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.propertyGrid,

this.listViewColumns,

this.panel1});

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;

this.Name = "ColumnEditorForm";

this.ShowInTaskbar = false;

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;

this.Text = "ColumnEditorForm";

this.panel1.ResumeLayout(false);

this.ResumeLayout(false);

Quote:
}

#endregion

#region Events

private void OnOkClick(object sender, EventArgs e)

{

//Delete the removed Columns

for (int i = 0; i < this.myDelCollection.Count; i++)

{

this.MyControl.RemoveColumn(this.myDelCollection[i].ColumnText);

this.MyControl.Columns.Remove(this.myDelCollection[i]);

this.DestroyInstance(this.myDelCollection[i]);

Quote:
}

//Write my Items to Columns

for (int i = 0; i < this.myCollection.Count; i++)

{

//this.editor.context.OnComponentChanging();

this.MyControl.AppendColumnToMe(myCollection[i]);

this.MyControl.Columns.Add(myCollection[i]);

GridControlXColumn col =
(GridControlXColumn)this.CreateInstance(typeof(GridControlXColumn));

col = myCollection[i];

//this.editor.context.OnComponentChanged();

Quote:
}

this.Close();

Quote:
}

private void buttonCancel_Click(object sender, System.EventArgs e)

{

this.MyControl.Refresh();

this.Close();

Quote:
}

private void listViewColumns_SelectedIndexChanged(object sender,
System.EventArgs e)

{

int row = this.listViewColumns.FocusedItem.Index;

if (row == -1)

return; //The the row has been deleted

string text = this.listViewColumns.Items[row].Text;

for (int i = 0; i < this.MyControl.Columns.Count; i++)

{

if (this.MyControl.Columns[i].ColumnText == text)

{

this.propertyGrid.SelectedObject = this.MyControl.Columns[i];

this.SelectedColumn = this.MyControl.Columns[i];

break;

Quote:
}
}

for (int i = 0; i < this.myCollection.Count; i++)

{

if (this.myCollection[i].ColumnText == text)

{

this.propertyGrid.SelectedObject = this.myCollection[i];

this.SelectedColumn = this.myCollection[i];

break;

Quote:
}
}
}

private void propertyGrid_PropertyValueChanged(object s,
System.Windows.Forms.PropertyValueChangedEventArgs e)

{

//this.AddColumnsToList();

Quote:
}

private void buttonAddColumn_Click(object sender, System.EventArgs e)

{

switch (this.comboBoxColumnStyle.Text)

{

case "ComboBox":

{

this.MyControl.AppendColumn("new.......", 90,
GridControlX.GridControlColumnStyles.ComboBox);

break;

Quote:
}

default:

{

//GridControlXColumn col =
(GridControlXColumn)this.CreateInstance(typeof(GridControlXColumn));

GridControlXColumn col = new GridControlXColumn("new....");

//col.ColumnText = "new....";

col.Width = 90;

//this.MyControl.AppendColumnToMe(col);

this.listViewColumns.Items.Add(col.ColumnText);

this.myCollection.Add(col);

//this.MyControl.Columns.Add(col);

break;

Quote:
}
}

//this.AddColumnsToList();

Quote:
}

private void buttonDeleteColumn_Click(object sender, System.EventArgs e)

{

string text = "";

int row = this.listViewColumns.FocusedItem.Index;

text = this.listViewColumns.Items[row].Text;

this.propertyGrid.Focus();

this.listViewColumns.Items[row].Remove();

for (int i = 0; i < this.MyControl.Columns.Count; i++)

{

if (this.MyControl.Columns[i].ColumnText == text)

this.myDelCollection.Add(this.MyControl.Columns[i]);

Quote:
}
}

#endregion

#region Helper Functions

private void AddColumnsToList()

{

this.listViewColumns.Items.Clear();

for (int i = 0; i < this.MyControl.Columns.Count; i++)

{

this.listViewColumns.Items.Add(this.MyControl.Columns[i].ColumnText);

Quote:
}
}

private void InitComboBox()

{

this.comboBoxColumnStyle.Items.Add(GridControlX.GridControlColumnStyles.Chec
kBox.ToString());

this.comboBoxColumnStyle.Items.Add(GridControlX.GridControlColumnStyles.Comb
oBox.ToString());

this.comboBoxColumnStyle.Items.Add(GridControlX.GridControlColumnStyles.Text
Box.ToString());

this.comboBoxColumnStyle.Text =
GridControlX.GridControlColumnStyles.TextBox.ToString();

Quote:
}

#endregion

Quote:
}

#endregion

private GridControlX MyControl = null;

public ITypeDescriptorContext context;

public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)

{

IWindowsFormsEditorService iWinFormEditService = null;

DesignerTransaction trans = null;

//bool local2;

IComponentChangeService iccs = null;

IDesignerHost idh = null;

//CheckoutException local5;

//object local6;

//object[] local7;

GridControlX instance = null;

ColumnForm edit = null;

#region Runtime Handling

//For the Runtime

if ( ((GridControlX)context.Instance).Site == null ||
((GridControlX)context.Instance).Site.DesignMode == false)

{

instance = (GridControlX)context.Instance;

edSvc =
(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorSe
rvice));

edit = new ColumnForm(this, instance);

edSvc.ShowDialog(edit);

return edit.EditValue;

Quote:
}

#endregion

instance = (GridControlX)context.Instance;

this.MyControl = instance;

if (this.MyControl.Site.DesignMode != true)

return null;

iWinFormEditService =
(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorSe
rvice));

this.context = context;

idh = (IDesignerHost)this.MyControl.Site.GetService(typeof(IDesignerHost));

if (idh != null)

{

trans = idh.CreateTransaction("Column Editing");

iccs =
(IComponentChangeService)this.MyControl.Site.GetService(typeof(IComponentCha
ngeService));

iccs.ComponentChanged += new
System.ComponentModel.Design.ComponentChangedEventHandler(this.OnComponentCh
anged);

iccs.ComponentChanging += new
System.ComponentModel.Design.ComponentChangingEventHandler(this.OnComponentC
{*filter*});

Quote:
}

edit = new ColumnForm(this, instance);

//context.OnComponentChanging();

iWinFormEditService.ShowDialog(edit);

trans.Commit();

//context.OnComponentChanged();

iccs.ComponentChanged -= new
System.ComponentModel.Design.ComponentChangedEventHandler(this.OnComponentCh
anged);

iccs.ComponentChanging -= new
System.ComponentModel.Design.ComponentChangingEventHandler(this.OnComponentC
{*filter*});

return edit.EditValue;

Quote:
}

private void OnComponentChanging(object sender, ComponentChangingEventArgs
e)

{

if (sender != this.context.Instance)

{

this.context.OnComponentChanging();

Quote:
}
}

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)

{

if (sender != this.context.Instance)

{

this.context.OnComponentChanged();

Quote:
}
}
}

#endregion


Sun, 08 May 2005 21:11:17 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. HOWTO : Design-time custom collection editing for custom control

2. How to Make a Custom Collection Editor

3. Binding a DataGrid Web Control to a Collection of Custom Classes

4. help with custom controls and collections

5. Custom controls and VC.NET dialog editor

6. Adding Custom Controls To Dialog Editor Toolbox

7. Displaying custom controls in resource editor

8. Custom control in dialog editor?

9. Accessing control array controls using the controls collection

10. help for split window with rich editor view or rich editor control

11. Collections Property editor

12. Collection editor

 

 
Powered by phpBB® Forum Software