Windows Develop Bookmark and Share   
 index > Windows Forms Designer > UITypeEditor and making property value available during runtime
 

UITypeEditor and making property value available during runtime

I have a UItypeeditor dialogwhich configures a datagridview columns. The columns are added to a listbox in the Uitypeeditior formand then assigned to a custom property of the user control. The custom property assigned is of object type. But during runtime the value of the custom property is just null. How can I get the valuesconfigured inUITypeEditior dialog during runtime?

Amit Gadre  Monday, September 14, 2009 9:06 AM
Let me see if I understood correctly: The changes made to a collection of yours during design time is not being persisted, meaning that you can add columns in Visual Studio but when you press F5 the columns are gone?

If yes, then you need to mark the property holding the collection with the DesignerSerializationVisibilityAttribute attribute. Use Content. You'll see the option. :-)
MCP
webJose  Monday, September 14, 2009 3:18 PM

We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 21, 2009 5:34 AM
Thanks Jose. That worked perfectly but currently facing another problem. I am able to configure the columns for the grid during design time and also the columns are visible during runtime as per configured. But when coming back to design time and attempting to display the editor dialog its showing an error "Unable to cast object of type WindowsApplication1.SYColumns to type WindowsApplication1.SYColumns". SYColumns is the custom property type for the control. The code snippet where the error occurred is as follows with bold:

public

 

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

{

 

if (context != null && provider != null)

{

 

//ssdb = ((SSDBCombo)context.Instance);

WindowsApplication1.

UserControlForm m_EditControl = new UserControlForm();

 

//SSDBCombo ssdb = context.Instance as SSDBCombo;

 

SYColumns SyCol = (SYColumns)value; //ERROR OCCURRED HERE

 

 

//ssdb.DBColumnsCols = SyCol;

 

//MessageBox.Show("EditValue 1");

IEditiorService = (

IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

 

if (IEditiorService != null)

{

 

MessageBox.Show("5");

 

//ssdb.DBColumnsCols = SyCol;

 

//MessageBox.Show("EditValue 4");

 

if (value != null)

{

 

MessageBox.Show("6");

 

MessageBox.Show(SyCol.ToString());

 

//ssdb.DBColumnsCols = (SYColumns)value;

 

if (SyCol.ColHeaderText != null & SyCol.ColNames != null)

{

 

MessageBox.Show("7");

 

//MessageBox.Show(SyCol.ColNames.Split(new char[] { ',' }).Length.ToString());

 

if (SyCol.ColNames.Trim() != "" && SyCol.ColHeaderText.Trim() != "")

{

 

for (int h = 0; h < SyCol.ColNames.Split(new char[] { ',' }).Length; h++)

{

 

if (SyCol.ColNames.Split(new char[] { ',' })[h].ToString() != "")

{

m_EditControl.lstCols.Items.Add(SyCol.ColNames.Split(

new char[] { ',' })[h].ToString() + "-" + SyCol.ColHeaderText.Split(new char[] { ',' })[h].ToString());

}

 

//MessageBox.Show(SyCol.ColNames.Split(new char[] { ',' })[h].ToString());

}

}

}

}

 

//m_EditControl.ShowDialog();

IEditiorService.ShowDialog(m_EditControl);

 

//if (IEditiorService.ShowDialog(m_EditControl) == DialogResult.OK)

 

//{

 

if (m_EditControl.lstCols.Items.Count > 0)

{

SyCol.ColNames =

"";

SyCol.ColHeaderText =

"";

 

for (int z = 0; z < m_EditControl.lstCols.Items.Count; z++)

{

SyCol.ColNames = SyCol.ColNames + m_EditControl.lstCols.Items[z].ToString().Substring(0, m_EditControl.lstCols.Items[z].ToString().IndexOf(

"-")) + ",";

SyCol.ColHeaderText = SyCol.ColHeaderText + m_EditControl.lstCols.Items[z].ToString().Substring(m_EditControl.lstCols.Items[z].ToString().IndexOf(

"-") + 1) + ",";

SyCol.ColNames = SyCol.ColNames.Trim();

SyCol.ColHeaderText = SyCol.ColHeaderText.Trim();

}

SyCol.ColNames = SyCol.ColNames.TrimEnd(

new char[] { ',' });

SyCol.ColHeaderText = SyCol.ColHeaderText.TrimEnd(

new char[] { ',' });

SyCol.ColsCount = SyCol.ColNames.Split(

new char[] { ',' }).Length;

}

 

//}

ConfigureDataGrid((

SSDBCombo)context.Instance);

 

return SyCol;

}

}

 

return base.EditValue(context, provider, value);

}

Kindly assist in resolving this issue.

Amit Gadre  Wednesday, October 07, 2009 6:39 AM
I see a lot of code in there.  Did you create your very own collection editor?  Because .Net provides a collection editor that works just beautifully.  All you have to do is a few overrides and that is it.
MCP
webJose  Wednesday, October 07, 2009 2:26 PM
No I did not create any collection editor. Is this the cause of the error? Because everything is working fine. Only that particular error is the concern. Can you please identify the cause of the error?
Amit Gadre  Thursday, October 08, 2009 5:03 AM

You can use google to search for other answers

Custom Search

More Threads

• IDesignerLoaderHost Interface
• How to make a Text Area with interactive text in a winform with VB.Net?
• C# Web Browser/File Association - all within Windows Application
• User Control Events
• How to I avoid a control becoming a child of a container in the designer?
• collection of groups with collection of controls not removing instances of controls from code
• Problem with SerialPort Read - Urgent
• Is it possible to hide third column if two columns are assigned to a ListView control ?
• Password in PropertyGrid
• How to format money with $, commas and 2 decimal in textbox?