473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Properties window - accessing collections

I have created a user control that includes the following field:
[Browsable(true)]
protected TreeColumn[] columns = new TreeColumn[3];

This is accessed via an accessor as follows:
pubilc TreeColumn[] Columns
{
get { return columns; }
set { columns = value; }
}

Now, at design time, I can see the "Columns" property in the property editor
and I can expand it to show three items. However, I want to be able to
change the values of these three columns, but VS has made them read only, so
will not let me make any changes.

Any suggestions as to how I get access to the public properties of the
TreeColum class?

On a second point, I get a button I can click that opens the collection
editor. This gives me add and remove buttons that are not helpful. I need my
array fixed at 3 items. Pressing the add button causes an error message -
can I either suppress the collection editor or can I remove these buttons?

Thanks
Steve
Mar 23 '06 #1
6 3422
Hi.
Use class inherited from ExpandableObjectConverter and its CanConvertTo and
CanConvertFrom methods for editing or displaying the items of your array. You
can find detailed info in MSDN.
The second question is still opened even for me. I do not know how to
disable/suppress collection editor button in the property grid too. Does
anybody know?
Thanks.
Apr 12 '06 #2
You will have to write a custom editor for you're spefic attributes and
specy that UIEditor in the attributes of the item. This will then display
you're own editor -- without using the default Collections editor -- hence
no button.

Jamie
"Brko" <Br**@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
Hi.
Use class inherited from ExpandableObjectConverter and its CanConvertTo
and
CanConvertFrom methods for editing or displaying the items of your array.
You
can find detailed info in MSDN.
The second question is still opened even for me. I do not know how to
disable/suppress collection editor button in the property grid too. Does
anybody know?
Thanks.

Apr 12 '06 #3
Hi. Thanks. I found this solution too. But when I created my own UIEditor it
didn't work for the property of the List<MyClass> type. May be List<> generic
defines its own CollectionEditor. I tryied to create my own editor for other
types and it worked. Does anybody know how to change UIEditor for the List<>
generic?
Thanks once more time.
B.
Apr 13 '06 #4
Here's s simple one I use -- this works OK, the dialog tha tthis code is
showing is just a simple 2 column datagrid view with key value pairs -- it
seems similar to what you are trying to do.

class CostEditor : UITypeEditor
{
private IWindowsFormsEditorService editorService = null;

public override UITypeEditorEditStyle
GetEditStyle(System.ComponentModel.ITypeDescriptor Context context)
{
return UITypeEditorEditStyle.Modal;
}

public override object EditValue(
ITypeDescriptorContext context,
IServiceProvider provider,
object value)
{
if (provider != null)
{
editorService =
provider.GetService(
typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
}

if (editorService != null)
{
Prices frm = new Prices((Dictionary<string, decimal>)value);
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK) return value;
}

return null;

}

Then where you define the Property you need the following

[Description("This indicate whether this is a menu that is
called on start of a POS device."),
Category("Prices"),
Editor(typeof(CostEditor), typeof(UITypeEditor))]
/// <Summary>
/// Returns the prices for all plans that apply to this item
/// </Summary>
public Dictionary<string, decimal> Prices
{
get { return _Prices; }
}

This way still presents the button to display the editor, but it displays my
grid not the default collection editor. My DataGridView is disabled for
editing, but if you allow editing and define the set in the property, and
also define the attribute [ReadOnly(False)] this will allow you to edit
you're values in you;re own dialog.

Hope this helps

Jamie
"Brko" <Br**@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hi. Thanks. I found this solution too. But when I created my own UIEditor
it
didn't work for the property of the List<MyClass> type. May be List<>
generic
defines its own CollectionEditor. I tryied to create my own editor for
other
types and it worked. Does anybody know how to change UIEditor for the
List<>
generic?
Thanks once more time.
B.

Apr 13 '06 #5
Now you opened my eyes. The problem of my code is that, I didn't inherit my
editor class directly from UITypeEditor but from CollectionEditor class which
is ancestor of UITypeEditor. I just wanted to suppress displaying the edit
button in the PropertyGrid for some conditions. But it seem to be impossible
to inherit correctly the new class from the CollectionEditor class. When I
put the breakpoint into the constructor of the class inherited of
CollectionEditor the programm doesn't stop there. Probably my editor is not
created even I specified the EditorAttribute correctly for my property.

This is non-properly working code:
public class iSTConfigVar
{
public string name = string.Empty;
public string value = string.Empty;
}

public class BLVarsEditor : CollectionEditor
{
public BLVarsEditor()
: base(typeof(List<iSTConfigVar>))
{
}

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext
context)
{
return UITypeEditorEditStyle.None;
//return base.GetEditStyle(context);
}
}

private List<iSTConfigVar> tralala = new List<iSTConfigVar>();

[EditorAttribute(typeof(BLVarsEditor), typeof(CollectionEditor))]
public List<iSTConfigVar> TestListGenericValue
{
get
{
return tralala;
}
set
{
tralala = value;
}
}
This is working code:
public class iSTConfigVar
{
public string name = string.Empty;
public string value = string.Empty;
}

public class BLVarsEditor : UITypeEditor
{
public BLVarsEditor()
{
}

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext
context)
{
return UITypeEditorEditStyle.None;
//return base.GetEditStyle(context);
}
}

private List<iSTConfigVar> tralala = new List<iSTConfigVar>();

[EditorAttribute(typeof(BLVarsEditor), typeof(UITypeEditor))]
public List<iSTConfigVar> TestListGenericValue
{
get
{
return tralala;
}
set
{
tralala = value;
}
}

The only difference is, the first editor is inherited directly from
UITypeEditor and the second is inherited from CollectionEditor.

Thanks for any help.
B.
Apr 13 '06 #6
I forgot to write question. Does anybody know if it is possible inherit class
from the CollectionEditor and change the behavior of newly inherited class?
Thanks.
B.
Apr 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Guy | last post by:
Guys Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time I have written a control by inheriting from the Button control....
3
by: Ryan Steckler | last post by:
I found this behavior while trying to implement a singleton class. Below is a somewhat more straight forward example, though admittedly less useful in real life. The basic problem is that when a...
3
by: Andre Boeder | last post by:
In one of my test classes there is a code fragment like this: protected System.Collections.Hashtable pData; public System.Collections.Hashtable PData { get { //TODO: read PData from DB...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
5
by: Simon | last post by:
Hi all, We have an ASP.NET 1.1 application running on IIS6 on Server 2003. Most of the base objects we are using in this application are taken from a windows application also written by us. We...
6
by: Steve Barnett | last post by:
I have created a user control that includes the following field: protected TreeColumn columns = new TreeColumn; This is accessed via an accessor as follows: pubilc TreeColumn Columns { get {...
14
by: Aaron Gray | last post by:
Hi, I want to access the properties of an IFrame but seem unable to get access to the IFrames document body. <html> <body> <iframe src="test.html" id="IFrame"></iframe> </body>
4
by: Shak | last post by:
Hi My code looks like the follwing: namespace A.B.C { .... private void foo() { A.B.C.Properties.Settings.Default.Save();
3
by: Alex | last post by:
Hi all, I'm trying to create an arraylist of a user control class... I'm able to define the list and add objects (panels) to it, but I can access and of the panel properties using an index... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.